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.22Hard
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.23Hard
What happens if you declare a variable but don't initialize it in C?
Answer: B
Uninitialized local variables contain garbage values (unpredictable values from previous memory contents). Global and static variables are automatically initialized to 0, but local variables are not.
Q.24Hard
Consider: int *ptr = NULL; *ptr = 5; What will happen?
Answer: B
Attempting to dereference a NULL pointer causes undefined behavior, typically resulting in a segmentation fault (runtime error). A NULL pointer doesn't point to valid memory.
Q.25Hard
What does the 'volatile' keyword indicate in C?
Answer: A
The volatile keyword tells the compiler that a variable's value may change unexpectedly (e.g., due to hardware, interrupts, or other threads), preventing compiler optimizations that assume the value doesn't change.
Advertisement
Q.26Hard
Consider: int *ptr; int arr[] = {1,2,3}; ptr = arr; What is ptr[1]?
Answer: B
When ptr points to the array arr, ptr[1] is equivalent to *(ptr+1), which accesses the second element of the array, which is 2.
Q.27Hard
What is the difference between getchar() and scanf("%c", &ch); in C?
Answer: C
getchar() specifically reads a single character from the standard input stream, while scanf("%c", &ch) is a formatted input function. getchar() is more straightforward for reading single characters.
Q.28Hard
Which of the following correctly describes the relationship between arrays and pointers in C?
Answer: B
In C, when an array name is used in most contexts, it decays (converts) to a pointer to its first element. For example, in int arr[5];, arr behaves like &arr[0]. However, arrays and pointers are not identical; arrays have fixed size while pointers are variables.
Q.29Hard
What is the difference between a function declaration and a function definition in C?
Answer: A
A function declaration (or prototype) tells the compiler about the function's name, return type, and parameters. A function definition includes the declaration along with the function body containing the actual implementation. Declaration is optional if the function is defined before use.
Q.30Hard
Which of the following is the correct way to declare a pointer to a function that returns an int and takes two int parameters?
Answer: B
The correct syntax for a function pointer is: int (*ptr)(int, int);. The parentheses around (*ptr) are necessary to indicate that ptr is a pointer to a function, not a function returning a pointer. Option A declares a function returning an int pointer.
Q.31Hard
Consider: int *p, q; What is the type of q?
Answer: B
Only p is declared as a pointer (int *p). The variable q is declared as a regular integer (int q). The * applies only to p in this declaration.
Q.32Hard
What is printed by: char s[] = "hello"; printf("%zu", sizeof(s));?
Answer: B
sizeof(s) includes the null terminator '\0'. "hello" has 5 characters + 1 null terminator = 6 bytes. If s was a pointer, sizeof would give pointer size.
Q.33Hard
What will be the result of: 5 % 2 * 23?
Answer: B
Modulus, multiplication, and division have equal precedence (left-to-right): (5 % 2) = 1, then (1 * 3) = 3, then (23) = 1 (integer division). Answer is 1, not 2. Correction: 1 is correct.
Q.34Hard
In a struct, how is memory allocated for union members?
Answer: B
In a union, all members share the same memory location. The size of the union equals the size of the largest member. Only one member can hold a value at a time.
Q.35Hard
What is the difference between #include <stdio.h> and #include "stdio.h"?
Answer: D
Using <> tells the compiler to search in standard system directories. Using "" tells it to search in the current directory first, then system directories. Generally, "" is used for user-defined headers and <> for standard library headers.
Q.36Hard
Consider the code: int *p; int arr[5]; p = arr; What does p[2] represent?
Answer: B
When p points to arr, p[2] is equivalent to *(p+2) and accesses the value at arr[2]. Pointers and array names decay to pointers, and pointer indexing retrieves the value.
Q.37Hard
Which of the following will correctly allocate memory for an array of 10 integers?
Answer: B
malloc() allocates memory in bytes. To allocate for 10 integers, we need 10 * sizeof(int) bytes. Option A allocates only 10 bytes, insufficient for 10 integers.
Q.38Hard
What will be the output of: int x = 5; int y = x++ + ++x; ?
Answer: D
This expression involves modifying the same variable (x) multiple times without an intervening sequence point. This is undefined behavior in C, and the result cannot be predicted reliably.
Q.39Hard
What is the output of this recursive function?
int func(int n) {
if(n <= 1) return 1;
return n * func(n-1);
}
printf("%d", func(4));
What is the output of this code involving bitwise operations?
int x = 5; // binary: 0101
int y = 3; // binary: 0011
printf("%d", x ^ y); // XOR operation
Answer: A
XOR operation: 5 ^ 3. Binary: 0101 ^ 0011 = 0110 = 6. XOR returns 1 when bits are different, 0 when same.