Govt Exams
int x = 5;
int y = ++x;
printf("%d %d", x, y);
++x is pre-increment, which increments x before assignment. So x becomes 6, then y is assigned 6. Both x and y are 6.
int main() {
int a = 10;
printf("%d", a += 5);
return 0;
}
The += operator adds 5 to a (a = a + 5 = 10 + 5 = 15), and printf prints the updated value 15.
In C, array indices are 0-based. arr[1][2] refers to the element in the second row (index 1) and third column (index 2) of the 2D array.
getchar() reads a single character from standard input (stdin). While fgetc() can also read a character, getchar() is the standard dedicated function for this purpose.
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.
C uses row-major order to store 2D arrays in memory. The elements are stored row by row sequentially in memory.
The do-while loop executes the body first and then checks the condition, ensuring at least one execution. while and for loops check the condition first.