What will be the memory size of the following struct?
struct Point { int x; char c; int y; }
Answer: C
Due to memory alignment/padding: int x (4 bytes), char c (1 byte) + 3 bytes padding, int y (4 bytes) = 12 bytes total. The compiler adds padding to align data members to their natural boundaries for efficient memory access.
Q.42Medium
What is the correct way to initialize an array of 5 integers with all elements as 0?
Answer: C
Both {} and {0} will initialize all array elements to 0. When you provide fewer initializers than array size, remaining elements are automatically set to 0.
Q.43Medium
Which of the following correctly declares a pointer to a pointer?
Answer: B
A pointer to a pointer is declared using two asterisks (). int ptr declares a pointer that points to another pointer that points to an integer.
Q.44Easy
What is the output of sizeof(char) in C?
Answer: B
By the C standard, sizeof(char) is always 1 byte. A char is the smallest addressable unit in C and is defined to be 1 byte.
Q.45Medium
What is the scope of a variable declared inside a function in C?
Answer: B
Variables declared inside a function have local scope (also called function scope). They are only accessible within that function and are destroyed when the function returns.
Advertisement
Q.46Easy
How many times will the loop execute?
for(int i = 0; i < 5; i++)
Answer: B
The loop initializes i to 0 and continues while i < 5. Values of i: 0, 1, 2, 3, 4. After i becomes 5, the condition is false, so the loop executes 5 times.
Q.47Medium
What is the difference between calloc() and malloc() in C?
Answer: D
calloc() allocates memory and initializes all bytes to 0, takes (number of elements, size of each element). malloc() just allocates memory without initialization and takes total size. calloc() is slightly slower due to initialization.
Q.48Easy
What will be the value of x after: int x = 5; x += 3;
Answer: C
The += operator is a compound assignment operator. x += 3 is equivalent to x = x + 3. Therefore, 5 + 3 = 8.
Q.49Medium
What is the correct syntax to open a file in C?
Answer: A
The correct syntax is FILE *fp = fopen("filename", "mode");. fopen() returns a pointer to a FILE structure, and the mode string specifies how to open the file ("r" for read, "w" for write, etc.).
Q.50Medium
Consider the following code:
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
What is the value of *(ptr + 2)?
Answer: C
ptr points to arr[0]. ptr + 2 points to arr[2]. *(ptr + 2) dereferences to get the value at arr[2], which is 3. Pointer arithmetic moves by the size of the data type (integers).
Q.51Medium
What is the output of the following code?
for(int i = 1; i <= 3; i++) { if(i == 2) continue; printf("%d ", i); }
Answer: B
When i = 1, it prints 1. When i = 2, continue skips the printf() and moves to the next iteration. When i = 3, it prints 3. Output: 1 3
Q.52Hard
What happens when you try to access an array element beyond its size in C?
Answer: C
C does not perform bounds checking on arrays. Accessing beyond array bounds results in undefined behavior - it may access garbage values, crash, or seem to work without error. This is a common source of bugs.
Q.53Medium
What is the output of: int x = 10; printf("%d", x++); printf("%d", x);
Answer: B
x++ is post-increment. First printf uses current value (10), then x is incremented. Second printf uses new value (11). Output: 1011
Q.54Hard
Which of the following is the correct way to pass a string to a function in C?
Answer: D
Both char s[] (array notation) and char *s (pointer notation) are valid ways to pass strings to functions in C. C does not have a built-in string type; strings are represented as character arrays or pointers to char.
Q.55Easy
What is the size of int data type in a 32-bit system?
Answer: B
In a 32-bit system, the int data type typically occupies 4 bytes (32 bits). This is the standard size for integer types on most 32-bit architectures.
Q.56Easy
Which header file is required to use the printf() function?
Answer: B
The stdio.h (Standard Input Output) header file contains declarations for printf(), scanf(), and other input/output functions. It is essential for console I/O operations.
Q.57Easy
In C, which operator has the highest precedence?
Answer: C
Parentheses have the highest precedence in C. Expressions within parentheses are evaluated first, followed by arithmetic operators, then logical operators, and finally assignment operators.
Q.58Easy
What is the purpose of the break statement in a loop?
Answer: B
The break statement exits or terminates the current loop immediately. Option D describes continue (which skips to next iteration), while break actually exits the loop.
Q.59Medium
Which of the following correctly declares a pointer to an integer?
Answer: A
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates that ptr is a pointer. The placement of * before the variable name is crucial.
Q.60Medium
What will be printed if char ch = 'A'; printf("%d", ch); is executed?
Answer: B
When %d format specifier is used with a char variable, it prints the ASCII value. The ASCII value of 'A' is 65. If it were 'a', the value would be 97.