Which of the following does not initialize ptr to null (assuming variable…
2026
Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0)?
Answer: A. int*ptr=&a; — To determine which option does not initialize ptr to null, analyze each option: Option A: int*ptr=&a; assigns the address of a to ptr. Since a is a valid…
- A.
int*ptr=&a;
- B.
int *ptr = &a- &a;
- C.
int *ptr=a-a;
- D.
none of these
Attempted by 309 students.
Show answer & explanation
Correct answer: A
To determine which option does not initialize ptr to null, analyze each option:
Option A: int*ptr=&a; assigns the address of a to ptr. Since a is a valid variable, ptr points to a memory location and is not null.
Option B: int *ptr = &a - &a; subtracts the address of a from itself, resulting in 0. Assigning 0 to a pointer initializes it to null.
Option C: int *ptr = a - a; subtracts a from itself, resulting in 0. Assigning 0 to a pointer initializes it to null.
Option D: 'none of these' implies that all options initialize ptr to null. However, Option A does not, so this option is incorrect.
Therefore, the option that does not initialize ptr to null is Option A.