Dereferencing *ptr without initialization leads to undefined behavior or runtime error.
Final Answer:
Pointer ptr is not initialized before dereferencing -> Option A
Quick Check:
Uninitialized pointer dereference = error [OK]
Hint: Always initialize pointer before using *ptr [OK]
Common Mistakes:
Dereferencing pointer before assigning address
Assuming declaration initializes pointer
Ignoring runtime errors from uninitialized pointers
5. Given the code below, which pointer declaration correctly allows p to point to a constant integer value?
const int val = 100;
// Which declaration is correct?
hard
A. int *p = &val;
B. const int *p = &val;
C. int *const p = &val;
D. int *p const = &val;
Solution
Step 1: Understand pointer to const int
To point to a constant integer, the pointer must be declared as pointing to a const int to prevent modification.
Step 2: Analyze options
int *p = &val; cannot assign const int* to int* (discards qualifiers). const int *p = &val; correctly declares pointer to const int. int *const p = &val; declares const pointer to int (type mismatch). int *p const = &val; invalid syntax.
Final Answer:
const int *p = &val; -> Option B
Quick Check:
Pointer to const int = const int *p [OK]
Hint: Use const int *p to point to constant int [OK]
Common Mistakes:
Using int *p to point to const int
Confusing const pointer and pointer to const
Misplacing const keyword
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.