Govt. Exams
Entrance Exams
#include
int main() {
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
This is a classic XOR swap algorithm. After three XOR operations, a and b exchange their values. Result: a=10, b=5.
#include
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.
int x = 5;
int *ptr = &x;
int **pptr = &ptr;
printf("%d", **pptr);
What is the output?
pptr is a pointer to pointer. **pptr dereferences twice: first to get ptr, then to get x's value which is 5.
register keyword suggests the compiler to store the variable in CPU register for faster access. Modern compilers often ignore this hint. You cannot take address of register variables.
volatile tells the compiler that a variable's value can change unexpectedly (e.g., in hardware registers or interrupt handlers), so it should not optimize away repeated reads.
10 % 3 = 1 (remainder), 10 / 3 = 3 (integer division). Output is '1 3'.
Static variables retain their value between function calls and are initialized only once. They persist for the lifetime of the program.
This is the ternary operator. Since 5 < 10 is true, b = 20. If false, b would be 30.
getchar() reads a single character from standard input and returns it. For strings, fgets() or scanf() is used.
'inline' is a hint to the compiler suggesting it should inline the function, though the compiler may ignore it.