AllInfoHub Logo

AllInfoHub – MCQ Practice

Pointers – Multiple Choice Questions (MCQs)

  1. 25. What are the potential problems caused by dangling pointers?

    • A. Program crashes
    • B. Memory leaks
    • C. Incorrect program behavior
    • D. All of the above
  2. 26. What is memory leakage in the context of pointers and dynamic memory allocation?

    • A. Failure to allocate memory
    • B. Failure to free dynamically allocated memory
    • C. Accessing memory out of bounds
    • D. Incorrect pointer arithmetic
  3. 27. Which standard library function is used to allocate a block of memory dynamically in C?

    • A. malloc()
    • B. free()
    • C. sizeof()
    • D. typedef()
  4. 28. Which standard library function is used to release a dynamically allocated block of memory in C?

    • A. malloc()
    • B. free()
    • C. sizeof()
    • D. typedef()
  5. 29. What is the purpose of the `sizeof()` operator when used with a pointer?

    • A. It returns the size of the data type pointed to by the pointer
    • B. It returns the size of the pointer itself
    • C. It returns the address stored in the pointer
    • D. It returns the number of elements the pointer can point to
  6. 30. What is the difference between `ptr++` and `(*ptr)++` if `ptr` is an integer pointer?

    • A. `ptr++` increments the pointer address by the size of an integer
    • B. `(*ptr)++` increments the value pointed to by the pointer
    • C. `ptr++` increments the value
    • D. `(*ptr)++` increments the address
  7. 31. What is the output of the following code? `int a = 10; int *ptr = &a; printf(\%d\"",*ptr);`"""

    • A. 10
    • B. The address of a
    • C. Error
    • D. 0
  8. 32. What is the output of the following code? `int arr[] = {1, 2, 3}; int *ptr = arr; printf(\%d\"",*(ptr + 2));`"""

    • A. 1
    • B. 2
    • C. 3
    • D. Error
  9. 33. What is the output of the following code? `int a = 5; int *ptr = &a; *ptr = 15; printf(\%d\"",a);`"""

    • A. 5
    • B. 15
    • C. The address of a
    • D. Error
  10. 34. What is the output of the following code? `int x = 20; int *p = &x; int **q = &p; printf(\%d\"",**q);`"""

    • A. The address of x
    • B. The address of p
    • C. 20
    • D. Error
  11. 35. What is the relationship between pointer arithmetic and array indexing?

    • A. `ptr[i]` is equivalent to `*(ptr + i)`
    • B. Pointer arithmetic only works with character pointers
    • C. Array indexing is faster than pointer arithmetic
    • D. There is no relationship
  12. 36. What is the purpose of using pointers with functions?

    • A. To modify the original variables passed to the function
    • B. To pass large data structures efficiently
    • C. To implement call by reference
    • D. All of the above