C Pointers-1
1. A pointer is a
a) variable that stores address of an instruction
b) variable that stores address of other variable
c) keyword used to create variables
d) None of these
Answer: B
A Pointer is a special variable which is used to store the address of another variable.
It is used to save memory space and achieve faster execution time.
2. The reason for using pointers in a Cprogram is
a) Pointers allow different functions to share and modify their local variables
b) To pass large structures so that complete copy of the structure can be avoided
c) Pointers enable complex “linked" data structures like linked lists and binary trees
d) All of the above
Answer: D
No explaination is given for this question.
3. How can you write a[i][j][k][l] in equivalent pointer expression?
a) (((***(a+i)+j)+k)+l)
b) ((**(*(a+i)+j)+k)+l)
c) (*(*(*(a+i)+j)+k)+l)
d) *(*(*(*(a+i)+j)+k)+l)
Answer: D
No explaination is given for this question.
4. What is the output of this C code?
int main() {
int i = 10;
void *p = &i;
printf("%d\n" (int)*p);
return 0;
}
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour
Answer: D
No explaination is given for this question.
5. Comment on the following pointer declaration?
int *ptr, p;
a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer
Answer: A
No explaination is given for this question.
6. What will be the output of the following C code?
void main() {
char *p;
p = "Hello";
printf("%c\n", *&*p);
}
a) Hello
b) H
c) Some address will be printed
d) None of these
Answer: B
* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.
7. The address operator &, cannot act on
a) R-values
b) Arithmetic expressions
c) Both of the above
d) Local variables
Answer: C
No explaination is given for this question.
8. Check whether the condition is correct or not?
int **a;
a) is illegal
b) is legal but meaningless
c) is syntactically and semantically correct
d) None of these
Answer: C
No explaination is given for this question.
9. What will be the output of the following program?
void main() {
int i = 10;
void *p = &i;
printf("%d\n", (int)*p;
}
a) Compiler time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behavior
Answer: A
p pointer of type void.
10. What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?
void main() {
int i = 10;
void *p = &i;
printf("%f\n", *(float *)p);
}
a) Error
b) 10
c) 0.0000000
d) None of these
Answer: C
No explaination is given for this question.