AllInfoHub Logo

AllInfoHub – MCQ Practice

Pointers – Multiple Choice Questions (MCQs)

  1. 37. What is the output of the following code? `void increment(int *n) { (*n)++; } int main() { int num = 5; increment(&num); printf(\%d\"",num); return 0; }`"""

    • A. 5
    • B. 6
    • C. Error
    • D. The address of num
  2. 38. What is the output of the following code? `int arr[] = {10, 20}; int *ptr = arr; printf(\%d %d\"",*ptr++,*ptr);` (Note: Order of evaluation might vary)"""

    • A. 10 10
    • B. 10 20
    • C. 20 20
    • D. Undefined behavior
  3. 39. What is the output of the following code? `int a = 1, b = 2; int *p1 = &a; int *p2 = &b; *p1 = *p2; printf(\%d %d\"",a,b);`"""

    • A. 1 2
    • B. 2 2
    • C. 1 1
    • D. The addresses of a and b
  4. 40. What is the output of the following code? `int arr[3] = {5, 10, 15}; int *ptr = arr + 2; printf(\%d\"",*ptr);`"""

    • A. 5
    • B. 10
    • C. 15
    • D. The address of 15
  5. 41. What is the output of the following code? `int num = 7; int *ptr = # printf(\%p\"",ptr);`"""

    • A. 7
    • B. The address of num in hexadecimal format
    • C. Error
    • D. A random memory address
  6. 42. What is the output of the following code? `int val = 3; int *p = &val; int *q = p; *q = 6; printf(\%d\"",val);`"""

    • A. 3
    • B. 6
    • C. The address of val
    • D. Error
  7. 43. What is the output of the following code? `int data[2] = {100, 200}; int *ptr1 = data; int *ptr2 = &data[1]; printf(\%d %d\"",*ptr1,*ptr2);`"""

    • A. 100 200
    • B. The addresses of 100 and 200
    • C. 200 100
    • D. Error
  8. 44. What is the output of the following code? `int value = 42; int *point = &value; printf(\%d\"",(*point)++); printf(\""%d\"""

    • A. value);`"
    • B. 42 42
    • C. 42 43
    • D. 43 42
  9. 45. What is the output of the following code? `int num_arr[] = {5, 10}; int *ptr_arr = num_arr; printf(\%d \"",*ptr_arr++); printf(\""%d\"""

    • A. *ptr_arr);`"
    • B. 5 5
    • C. 5 10
    • D. 10 5
  10. 46. What is a pointer to a constant integer in C?

    • A. A pointer that cannot be changed
    • B. A pointer that always points to the value 0
    • C. A pointer that points to an integer whose value cannot be changed
    • D. A constant pointer that points to a constant integer
  11. 47. How do you declare a pointer to a constant integer in C?

    • A. const int *ptr;
    • B. int const *ptr;
    • C. int * const ptr;
    • D. All of the above
  12. 48. What is a constant pointer to an integer in C?

    • A. A pointer that points to a constant integer
    • B. A pointer whose value (the address it stores) cannot be changed
    • C. A pointer that always points to the same memory location
    • D. Both B and C