Govt. Exams
Entrance Exams
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.
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.
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.