Here is a listing of online C test questions on “Pointers and Addresses” along with answers, explanations and/or solutions:
1. Which is an indirection operator among the following?
a) &
b) *
c) ->
d) .
Answer: b
Clarification: None.
2. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;)?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
Answer: a
Clarification: None.
3. What will be the output of the following C code?
-
#include -
int x = 0;
-
void main()
-
{ -
int *ptr = &x;
-
printf("%pn", ptr);
-
x++; -
printf("%pn ", ptr);
-
}
a) Same address
b) Different address
c) Compile time error
d) Varies
Answer: a
Clarification: None.
4. What will be the output of the following C code?
-
#include -
int x = 0;
-
void main()
-
{ -
int *const ptr = &x;
-
printf("%pn", ptr);
-
ptr++; -
printf("%pn ", ptr);
-
}
a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8
Answer: b
Clarification: None.
5. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 0;
-
int *ptr = &x;
-
printf("%pn", ptr);
-
ptr++; -
printf("%pn ", ptr);
-
}
a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 0;
-
int *ptr = &5;
-
printf("%pn", ptr);
-
}
a) 5
b) Address of 5
c) Nothing
d) Compile time error
Answer: d
Clarification: None.
7. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 0;
-
int *ptr = &x;
-
printf("%dn", *ptr);
-
}
a) Address of x
b) Junk value
c) 0
d) Run time error
Answer: c
Clarification: None.
