FSc · Computer Science (Grade 12)

Unit 7 MCQs

50 solved multiple choice questions with answers.

Q1. A pointer is a variable that stores

  1. AAddress of another variable
  2. BSize of another variable
  3. CValue of another variable
  4. DName of another variable
Show answer
Answer: A. Address of another variable
Report a mistake

Q2. The address-of operator is

  1. A->
  2. B&
  3. C::
  4. D*
Show answer
Answer: B. &
Report a mistake

Q3. The dereference operator is

  1. A:
  2. B&
  3. C*
  4. D.
Show answer
Answer: C. *
Report a mistake

Q4. Declaration of a pointer to an integer is

  1. A*int ptr;
  2. Bint ptr;
  3. Cint *ptr;
  4. Dint &ptr;
Show answer
Answer: C. int *ptr;
Report a mistake

Q5. After int x = 10; int *p = &x; the expression *p gives

  1. AAddress of p
  2. BValue of x
  3. CGarbage value
  4. DAddress of x
Show answer
Answer: B. Value of x
Report a mistake

Q6. Pointers are useful for

  1. AOnly constants
  2. BOnly loops
  3. CDynamic memory allocation
  4. DOnly static variables
Show answer
Answer: C. Dynamic memory allocation
Report a mistake

Q7. NULL pointer is a pointer that

  1. ACannot be declared
  2. BPoints to infinity
  3. CPoints to a valid variable
  4. DPoints to address 0
Show answer
Answer: D. Points to address 0
Report a mistake

Q8. A wild pointer is

  1. AA constant pointer
  2. BA pointer that has not been initialized
  3. CA pointer pointing to NULL
  4. DA pointer pointing to a valid object
Show answer
Answer: B. A pointer that has not been initialized
Report a mistake

Q9. The size of a pointer on a 64-bit system is usually

  1. A8 bytes
  2. B2 bytes
  3. C4 bytes
  4. D16 bytes
Show answer
Answer: A. 8 bytes
Report a mistake

Q10. Pointer arithmetic is valid with

  1. ADivision of two pointers
  2. BAll arithmetic operators equally
  3. CInteger addition/subtraction
  4. DMultiplication of two pointers
Show answer
Answer: C. Integer addition/subtraction
Report a mistake

Q11. If p points to an integer, p+1 points to

  1. APrevious integer
  2. BNext integer location
  3. CNext byte
  4. DSame location
Show answer
Answer: B. Next integer location
Report a mistake

Q12. The expression *(p+1) is equivalent to

  1. Ap[1]
  2. B&p[1]
  3. Cp+1
  4. DBoth a and c
Show answer
Answer: A. p[1]
Report a mistake

Q13. Array name itself acts as

  1. AA value
  2. BA function
  3. CA constant pointer to the first element
  4. DA variable pointer
Show answer
Answer: C. A constant pointer to the first element
Report a mistake

Q14. We cannot increment an array name because

  1. AArrays have no address
  2. BIt is a constant pointer
  3. CIt is a variable
  4. DIt is illegal syntax only
Show answer
Answer: B. It is a constant pointer
Report a mistake

Q15. A pointer to a pointer is declared as

  1. Aint **pp;
  2. Bint *pp;
  3. Cint pp**;
  4. Dint &pp;
Show answer
Answer: A. int **pp;
Report a mistake

Q16. Dynamic memory allocation in C++ is done using

  1. Anew operator
  2. BOnly static allocation
  3. COnly calloc
  4. Dmalloc only
Show answer
Answer: A. new operator
Report a mistake

Q17. Memory allocated by new is released using

  1. Aremove
  2. Bfree only
  3. Cdelete
  4. Dclear
Show answer
Answer: C. delete
Report a mistake

Q18. new int; allocates memory for

  1. AArray of integers
  2. BFloat
  3. COne integer
  4. DCharacter
Show answer
Answer: C. One integer
Report a mistake

Q19. new int[10]; allocates memory for

  1. A10 characters
  2. BArray of 10 integers
  3. COne integer
  4. DNothing
Show answer
Answer: B. Array of 10 integers
Report a mistake

Q20. delete[] is used for

  1. AReleasing memory allocated for arrays
  2. BReleasing single variable only
  3. CClearing screen
  4. DDeleting files
Show answer
Answer: A. Releasing memory allocated for arrays
Report a mistake

Q21. Memory leak occurs when

  1. APointer is NULL
  2. BDynamically allocated memory is not released
  3. CArray is too large
  4. DToo much stack is used
Show answer
Answer: B. Dynamically allocated memory is not released
Report a mistake

Q22. Dangling pointer is a pointer that

  1. APoints to NULL
  2. BPoints to memory that has been freed
  3. CHas not been initialized
  4. DPoints to a valid object
Show answer
Answer: B. Points to memory that has been freed
Report a mistake

Q23. this pointer is available in

  1. AGlobal functions
  2. Bmain() only
  3. CStatic member functions
  4. DNon-static member functions
Show answer
Answer: D. Non-static member functions
Report a mistake

Q24. this pointer points to

  1. ANULL
  2. BThe current object
  3. CGlobal variables
  4. DThe previous object
Show answer
Answer: B. The current object
Report a mistake

Q25. A constant pointer means

  1. APointer cannot be used
  2. BThe address stored in pointer cannot change
  3. CBoth address and value can change
  4. DThe value pointed to cannot change
Show answer
Answer: B. The address stored in pointer cannot change
Report a mistake

Q26. A pointer to constant means

  1. AThe address cannot change
  2. BThe value pointed to cannot be changed through the pointer
  3. CBoth can change
  4. DPointer is NULL
Show answer
Answer: B. The value pointed to cannot be changed through the pointer
Report a mistake

Q27. Declaration of constant pointer to integer is

  1. Aint * const p;
  2. Bconst int * const p;
  3. Cint const *p;
  4. Dconst int *p;
Show answer
Answer: A. int * const p;
Report a mistake

Q28. Declaration of pointer to constant integer is

  1. Aint * const p;
  2. Bconst * int p;
  3. Cconst int *p;
  4. Dint const p;
Show answer
Answer: C. const int *p;
Report a mistake

Q29. Function pointers are used to

  1. AStore address of a function
  2. BStore address of a variable only
  3. CAllocate memory
  4. DOnly call main()
Show answer
Answer: A. Store address of a function
Report a mistake

Q30. Syntax of function pointer is

  1. Areturn_type *ptr(parameter_list);
  2. Breturn_type ptr*(parameter_list);
  3. C*return_type ptr(parameter_list);
  4. Dreturn_type (*ptr)(parameter_list);
Show answer
Answer: D. return_type (*ptr)(parameter_list);
Report a mistake

Q31. Pointers can be used to implement

  1. AOnly classes
  2. BOnly static arrays
  3. CDynamic data structures (linked list, tree, etc.)
  4. DOnly loops
Show answer
Answer: C. Dynamic data structures (linked list, tree, etc.)
Report a mistake

Q32. The operator -> is used with

  1. APointers to objects / structures
  2. BFunctions only
  3. CArrays only
  4. DNormal variables
Show answer
Answer: A. Pointers to objects / structures
Report a mistake

Q33. ptr->member is equivalent to

  1. A(*ptr).member
  2. Bptr.member
  3. C*ptr.member
  4. D&ptr.member
Show answer
Answer: A. (*ptr).member
Report a mistake

Q34. Void pointer can point to

  1. AOnly integers
  2. BOnly characters
  3. COnly floats
  4. DAny data type
Show answer
Answer: D. Any data type
Report a mistake

Q35. Void pointer cannot be

  1. ADereferenced directly without casting
  2. BUsed at all
  3. CAssigned address
  4. DDeclared
Show answer
Answer: A. Dereferenced directly without casting
Report a mistake

Q36. Far pointer and near pointer concepts were used in

  1. AOnly Java
  2. BOnly Python
  3. CModern 64-bit systems only
  4. DOld 16-bit segmented memory models
Show answer
Answer: D. Old 16-bit segmented memory models
Report a mistake

Q37. Smart pointers in modern C++ are used to

  1. AReplace all variables
  2. BMake pointers faster
  3. CAutomatically manage memory and avoid leaks
  4. DIncrease memory usage
Show answer
Answer: C. Automatically manage memory and avoid leaks
Report a mistake

Q38. Examples of smart pointers are

  1. Aunique_ptr, shared_ptr, weak_ptr
  2. BOnly char*
  3. COnly void*
  4. DOnly int*
Show answer
Answer: A. unique_ptr, shared_ptr, weak_ptr
Report a mistake

Q39. Reference variable is

  1. AA function
  2. BA constant
  3. CAn alias for another variable
  4. DA pointer
Show answer
Answer: C. An alias for another variable
Report a mistake

Q40. Reference must be

  1. ALeft uninitialized
  2. BAlways NULL
  3. CA pointer
  4. DInitialized when declared
Show answer
Answer: D. Initialized when declared
Report a mistake

Q41. Difference between pointer and reference is

  1. APointer is safer
  2. BReference can point to many variables
  3. CPointer cannot be changed
  4. DReference cannot be NULL and must be initialized
Show answer
Answer: D. Reference cannot be NULL and must be initialized
Report a mistake

Q42. Passing large objects is efficient with

  1. ACall by value only
  2. BPointers or references
  3. COnly global variables
  4. DOnly arrays
Show answer
Answer: B. Pointers or references
Report a mistake

Q43. Returning a local variable by reference/pointer is

  1. ARecommended
  2. BDangerous (dangling reference)
  3. CCompulsory
  4. DAlways safe
Show answer
Answer: B. Dangerous (dangling reference)
Report a mistake

Q44. Pointer comparison is valid when

  1. AAlways valid for any pointers
  2. BBoth pointers point to the same array or object
  3. CNever valid
  4. DOnly with NULL
Show answer
Answer: B. Both pointers point to the same array or object
Report a mistake

Q45. The expression &(*p) is equal to

  1. A&p
  2. Bp
  3. C**p
  4. D*p
Show answer
Answer: B. p
Report a mistake

Q46. The expression *(&x) is equal to

  1. AAddress of x
  2. Bx
  3. C&x
  4. D*x
Show answer
Answer: B. x
Report a mistake

Q47. A pointer can be incremented using

  1. AOnly p = p * 2
  2. BNot possible
  3. COnly p = p / 2
  4. Dp++ or p = p + 1
Show answer
Answer: D. p++ or p = p + 1
Report a mistake

Q48. Base address of an array arr can be obtained by

  1. AOnly *arr
  2. BOnly &arr
  3. Carr or &arr[0]
  4. DOnly arr[0]
Show answer
Answer: C. arr or &arr[0]
Report a mistake

Q49. In C++, nullptr is preferred over NULL because

  1. AIt uses less memory
  2. BIt is type-safe
  3. CIt is compulsory
  4. DIt is faster
Show answer
Answer: B. It is type-safe
Report a mistake

Q50. The most important rule while using pointers is

  1. AAlways use wild pointers
  2. BNever use delete
  3. CAlways initialize them and free dynamically allocated memory
  4. DNever initialize them
Show answer
Answer: C. Always initialize them and free dynamically allocated memory
Report a mistake