C Pointers-2
1. What is wild pointer?
a) Pointer which is wild in nature
b) Pointer which has no value
c) Pointer which is not initialized
d) None
Answer: C
Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave badly.
2. In order to fetch the address of the variable we write preceding _________ sign before variable name.
a) Percent(%)
b) Comma(,)
c) Ampersand(&)
d) Asterisk(*)
Answer: C
& is used to get an address of the variable.
3. Address stored in the pointer variable is of type _______.
a) Integer
b) Float
c) Array
d) Character
Answer: A
No explaination is given for this question.
4. Comment on this const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) Both (a) and (b)
d) You can change the pointer as well as the value pointed by it
Answer: A
No explaination is given for this question.
5. The operator > and < are meaningful when used with pointers, if
a) The pointers point to data of similar type
b) The pointers point to structure of similar data type
c) The pointers point to elements of the same array
d) None of these
Answer: C
No explaination is given for this question.
6. What does this declaration means -
int (*p)[5];
a) p is one dimensional array of size 5, of pointers to integers
b) p is a pointer to a 5 elements integer array
c) The same as int *p[
d) None of these
Answer: B
No explaination is given for this question.
7. Which of the following is the correct ways of declaring a float pointer:
a) float ptr;
b) float *ptr;
c) *float ptr;
d) None of the above
Answer: B
No explaination is given for this question.
8. Find the output of the following program?
void main() {
char *msg = "hi";
printf(msg);
}
a) hi
b) h
c) hi followed by garbage value
d) None of Error
Answer: A
No explaination is given for this question.
9. Prior to using a pointer variable it should be
a) initialized
b) Declared
c) Both A and B
d) None of the above
Answer: A
p pointer of type void.
10. What will be the output of the program.
void main() {
printf("%d %d", sizeof(int *), sizeof(int **));
}
a) 2, 0
b) 0, 2
c) 2, 2
d) 2, 4
e) 4, 4
Answer: C
Every pointer regardless of its type whereas single pointer or pointer to pointer, needs only 2 bytes.
Size of pointer and int is 2 bytes in Turbo C compiler on windows 32 bit machine. So size of pointer is compiler specific. But generally most of the compilers are implemented to support 4 byte pointer variable in 32 bit and 8 byte pointer variable in 64 bit machine.