Question 1
Which of the following data types will result in the least memory allocation?
double
char
short
float
The IIT Madras BS Programming in C (Programming in C) End Term paper sat on 22 Dec 2024, in the September 2024 term, set QDB3: 25 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
Which of the following data types will result in the least memory allocation?
double
char
short
float
Correct answer
char
What is the scope of a variable declared inside a function in C?
Global
Local to the function
Accessible only in main()
Accessible in all functions called by the parent function
Correct answer
Local to the function
In little-endian format, the least significant byte is stored at the highest memory address.
In little-endian format, the most significant byte is stored at the lowest memory address.
In big-endian format, the most significant byte is stored at the lowest memory address.
In big-endian format, the least significant byte is stored at the lowest memory address.
Correct answer
In big-endian format, the most significant byte is stored at the lowest memory address.
What is the key distinction between stack and heap memory in C programming?
Stack memory is used for storing global variables, while heap memory is used for storing local variables.
Stack memory is automatically managed for function calls, while heap memory requires explicit allocation and deallocation.
Stack memory can grow indefinitely, while heap memory has a fixed size defined at compile time.
There is no difference; stack and heap memory serve the same purpose in C programming.
Correct answer
Stack memory is automatically managed for function calls, while heap memory requires explicit allocation and deallocation.
10
20
0
Compilation error
Correct answer
10
5
10
15
Compilation error
Correct answer
10
What will be the output of the following C program?
10
0
10
5
10
10
10
Garbage Value
Correct answer
10
10
A
B
C
D
Correct answer
B
10
20
30
40
Correct answer
30
Correct answer
Choose the correct statement for fscanf() and scanf().
fscanf() always reads from standard input whereas scanf() specifies a stream from which to read
fscanf() specifies a stream from which to read whereas scanf() reads only from standard input
fscanf() and scanf() have no difference in their functionalities
fscanf() and scanf() can read from any specified stream
Correct answer
fscanf() specifies a stream from which to read whereas scanf() reads only from standard input
Correct answer
9
6
8
7
Correct answer
8
Consider the following code to check whether the input number is Prime or not. Consider that input is a positive integer. However, it contains a logical error.
7
12
25
27
Correct answer
25
Counts the number of odd numbers from 1 to n.
Counts the number of even numbers from 1 to n.
The sum of odd numbers from 1 to n.
The sum of even numbers from 1 to n.
Correct answer
Counts the number of odd numbers from 1 to n.
Correct answer
6
2
14
1
Correct answer
14
25
11
27
36
Correct answer
36
Which of the following statement(s) is/are true regarding the “static” keyword in C?
A static variable inside a function retains its value between function calls.
A static global variable has file scope, meaning it is only accessible within the file where it is declared.
Static variables must be initialized at compile-time.
A static function can be called from other files of the same program.
Correct answers
A static variable inside a function retains its value between function calls.
A static global variable has file scope, meaning it is only accessible within the file where it is declared.
Which of the following statements about pointers is/are true?
A pointer can be incremented to point to the next memory location of its type.
A pointer variable cannot be reassigned after initialization.
Dereferencing a pointer gives the value stored at the memory address it holds.
Dereferencing a pointer gives the memory address it holds.
Correct answers
A pointer can be incremented to point to the next memory location of its type.
Dereferencing a pointer gives the value stored at the memory address it holds.
Which of the following statement(s) is/are true about unions in C?
Unions can contain members of different data types.
The size of a union is the sum of the sizes of all its members.
Unions can be nested within other unions or structures.
The size of a union is dynamically allocated based on the size of its members.
Correct answers
Unions can contain members of different data types.
Unions can be nested within other unions or structures.
Correct answer: 19
Consider the following code.
What will be the output of the program?
Correct answer: 2
Correct answer: 60
Correct answer: 7