Govt Exams
When p is a pointer to a structure, we cannot use p.x (dot notation) directly. The correct ways are: p->x (arrow operator) or (*p).x (dereference then dot operator). The notation p.x would be used only if p were a structure variable, not a pointer. Therefore, p.x is incorrect when p is a pointer.
The printf() function is defined in the Standard Input/Output library. Therefore, '#include <stdio.h>' must be included at the beginning of the program to use printf() and other I/O functions like scanf(), getchar(), putchar(), etc.
In array notation, arr is a pointer to the first element. *(arr + 3) dereferences the pointer that points to the 4th element (index 3). Since array indexing is 0-based: arr[0]=1, arr[1]=2, arr[2]=3, arr[3]=4. Therefore, *(arr + 3) = 4.
Both malloc() and calloc() allocate dynamic memory. The key difference is that malloc() allocates uninitialized memory (contains garbage values), while calloc() allocates memory and initializes all bytes to zero. calloc() also takes two arguments (number of elements and size of each element), while malloc() takes one (total bytes needed).
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?
int *ptr;
int arr[3] = {10, 20, 30};
ptr = arr;
printf("%d", *(ptr + 1));
ptr points to arr[0] (value 10). ptr + 1 points to arr[1] (value 20). *(ptr + 1) dereferences this pointer, giving 20.
The strlen() function returns the number of characters in a string, excluding the null terminator ('\0').