What is the difference between calloc() and malloc()?
Answer: D
calloc(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.
Q.102Medium
Which of the following is used to comment multiple lines in C?
Answer: B
/* */ is used for multi-line comments in C. // is used for single-line comments and was introduced in C99.
Q.103Medium
What will be the output of: float x = 25; printf("%f", x);
Answer: B
Since both 5 and 2 are integers, integer division occurs (25 = 2). The result 2 is then converted to float as 2.000000.
Q.104Medium
How are structures different from unions in C?
Answer: A
In structures, each member has its own memory location. In unions, all members share the same memory location, so only one can hold a value at a time.
Q.105Hard
What does the static keyword do when used with a global variable?
Answer: A
When static is used with a global variable, it restricts its scope to the file where it is declared. Without static, global variables are accessible across files using extern.
Advertisement
Q.106Hard
Consider: int arr[10]; int *p = arr; What is p[5] equivalent to?
Answer: C
Array name decays to pointer. p[5] is equivalent to *(p+5) which is *(arr+5) or arr[5]. This demonstrates pointer arithmetic.
Q.107Hard
What is the difference between declaration and definition in C?
Answer: B
Declaration tells the compiler about a variable's name and type (e.g., 'extern int x;'). Definition actually allocates memory (e.g., 'int x = 5;'). A variable can be declared multiple times but defined only once.
Q.108Medium
What will be the output of the following code?
int a = 5;
int b = ++a + a++;
printf("%d", b);
Answer: B
++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.
Q.109Easy
What is the size of an empty structure in C?
Answer: B
An empty structure in C has a size of 1 byte. This is to ensure each structure instance has a unique address in memory.
Q.110Easy
What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
Answer: A
strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.
Q.111Medium
What will be the output of: int x = 5; printf("%d", x << 1);
Answer: B
The left shift operator (<<) shifts bits to the left by 1 position, which is equivalent to multiplying by 2. So 5 << 1 = 10.
Q.112Medium
Consider the code: int arr[10]; int *p = arr; What is p[5]?
Answer: B
p points to arr, so p[5] is equivalent to *(p+5) which gives the value at arr[5].
Q.113Medium
What is the purpose of the void pointer in C?
Answer: D
The void pointer is a generic pointer that can hold addresses of any data type. void is also used for functions returning nothing and parameters.
Q.114Easy
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
Answer: A
The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)
Q.115Medium
Which function is used to read a string from standard input?
Answer: D
All three functions can read strings, though gets() is deprecated due to security issues. fgets() is safer as it limits input size.
Q.116Medium
What is the output of: int arr[] = {1,2,3,4,5}; printf("%d", sizeof(arr)/sizeof(arr[0]));
Answer: A
sizeof(arr) gives total size of array. sizeof(arr[0]) gives size of one element. Dividing gives the number of elements: 420 = 5.
Q.117Easy
Which of the following correctly initializes a 2D array?
Answer: C
Both syntaxes are correct. C allows initializing 2D arrays with or without explicit braces for each row.
Q.118Easy
What will be the output of: printf("%d", 25);
Answer: B
Integer division truncates the decimal part. 25 = 2 (not 2.5) because both operands are integers.
Q.119Easy
What does the getchar() function do?
Answer: A
getchar() reads a single character from standard input (stdin) and returns its ASCII value.
Q.120Easy
What will be the output of: int a = 5, b = 5; if(a == b) printf("Equal"); else printf("Not Equal");
Answer: A
The == operator compares values. Since a and b both have value 5, the condition is true and "Equal" is printed.