Govt. Exams
Entrance Exams
int x = 5; // binary: 0101
int y = 3; // binary: 0011
printf("%d", x ^ y); // XOR operation
XOR operation: 5 ^ 3. Binary: 0101 ^ 0011 = 0110 = 6. XOR returns 1 when bits are different, 0 when same.
int func(int n) {
if(n
This function calculates factorial. func(4) = 4 * func(3) = 4 * (3 * func(2)) = 4 * (3 * (2 * func(1))) = 4 * 3 * 2 * 1 = 24.
int a = 5, b = 2;
int result = a * b + ++b * a--;
printf("%d %d %d", result, a, b);
What will be the output?
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.
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.
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.
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.
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.
Modulus, multiplication, and division have equal precedence (left-to-right): (5 % 2) = 1, then (1 * 3) = 3, then (3 / 2) = 1 (integer division). Answer is 1, not 2. Correction: 1 is correct.
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.