C Pointers-3
1. What is the base data type of a pointer variable by which the memory would be allocated to it?
a) int
b) float
c) No datatype
d) Depends upon the type of the variable to which it is pointing
e) unsigned int
Answer: E
No explaination is given for this question.
2. Prior to using a pointer variable it should be
a) Declared
b) Initialized
c) Both declared and initalized
d) None of these
Answer: C
Using a pointer variable, without initializing it, will be disastrous, as it will have a garbage value.
3. In C a pointer variable to an integer can be created by the decalaration
a) int p*;
b) int *p;
c) int +p;
d) int $p;
Answer: B
No explaination is given for this question.
4. A pointer variable can be
a) Passed to a function
b) Changed within a function
c) Returned by a function
d) Can be assigned an integer value
Answer: C
No explaination is given for this question.
5. What will be the output of the following C code?
void main() {
int a[] = {1,2,3,4,5}, *p;
p = a;
++*p;
printf("%d ", *p);
p += 2;
printf("%d ", *p);
}
a) 24
b) 34
c) 22
d) 23
Answer: D
No explaination is given for this question.
6. What is the output of the following C code?
char *ptr;
char mystring[] = "abcdefg";
ptr = myString;
ptr += 5;
a) fg b) efg c) defg d) cdefg e) bcdefg
View AnswerAnswer: A
No explaination is given for this question.
7. Will this program compile?
int main() {
char str[5] = "LetsFind";
return 0;
}
a) True
b) False
Answer: A
C doesn't do array bounds checking at compile time, hence this compiles.But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.GCC would give you a warning.
8. Is the NULL pointer same as an uninitialised pointer?
a) True
b) False
Answer: B
No explaination is given for this question.
9. Which of the following statements correct about k used in the below statement?
char ****k;
a) k is a pointer to a pointer to a pointer to a char
b) k is a pointer to a pointer to a pointer to a pointer to a char
c) k is a pointer to a char pointer
d) k is a pointer to a pointer to a char
Answer: B
k is a pointer to a pointer to a pointer to a pointer to a char.
10. What will be the output of the program.
char *p = 0;
char *t = NULL;
a) Yes
b) No
Answer: B
NULL is #defined as 0 in the 'stdio.h' file. Thus, both p and t are NULL pointers.