Table of Contents
Pointers-mcqs
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
View Answer
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
View Answer
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;
View Answer
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
View Answer
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
View Answer
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) bcdefgView Answer
Answer: 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
View Answer
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
View Answer
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
View Answer
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
View Answer
Answer: B
NULL is #defined as 0 in the ‘stdio.h’ file. Thus, both p and t are NULL pointers
Discover more from EduGrown School
Subscribe to get the latest posts sent to your email.