Pointers in C Moodle
Pointers in C Moodle
Pointers in C Moodle
C. 2 4
D. 2 somegarbagevalue
ANSWER: D
Which of the following is not possible in C?
A. Array of function pointer
B. Returning a function pointer
C. Comparison of function pointer
D. None of the mentioned
ANSWER: D
What is the output of this C code?#include <stdio.h>void main(){int k = 5;int *p
= &k;int **m = &p;printf("%d%d%d\n", k, *p, **p);}
A. 5 5 5
B. 5 5 junk value
C. 5 junk junk
D. Compile time error
ANSWER: D
How many number of pointer (*) does C have against a pointer variable declaratio
n?
A. 7
B. 127
C. No limits
D. 255.
ANSWER: C
What is the output of this C code?#include <stdio.h>struct p{int x;int y;};int m
ain(){struct p p1[] = {1, 2, 3, 4, 5, 6};struct p *ptr1 = p1;printf("%d %d\n", p
tr1->x, (ptr1 + 2)->x);}
A. 1 5
B. 1 3
C. Compile time error
D. 1 4
ANSWER: A
Determine Output:main(){char *str1 = "abcd";char str2[] = "abcd";printf("%d %d %
d", sizeof(str1), sizeof(str2), sizeof("abcd"));}
A. 255
B. 244
C. 555
D. 245
ANSWER: A
Choose the best answer.Prior to using a pointer variable
A. It should be declared.
B. It should be initialized.
C. It should be both declared and initialized.
D. None of these.
ANSWER: C
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
The statement int **a;
A. is illegal
B. is legal but meaningless
C. is syntactically and semantically correct
D. None of these.
ANSWER: C
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
The declaration int (*p) [5];means
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
Which of the following is the correct way of declaring a float pointer:
A. float ptr;
B. float *ptr;
C. *float ptr;
D. None of the above
ANSWER: B
Find the output of the following program.void main(){printf("%d, %d", sizeof(int
*), sizeof(int **));}
A. 2, 0
B. 0, 2
C. 2, 2
D. 2, 4
ANSWER: C
Which of the following statements are true after execution of the program.void m
ain(){int a[10], i, *p;a[0] = 1;a[1] = 2;p = a;(*p)++;}
A. a[1] = 3
B. a[0] = 2
C. a[1] = 2
D. a[0] = 3
ANSWER: B
What is the base data type of a pointer variable by which the memory would be al
located to it?
A. int
B. unsigned int
C. No data type
D. Depends upon the type of the variable to which it is pointing.
ANSWER: B
What would be the output for the following Turbo C code?#include<stdioh>void mai
n(){int a[]={ 1, 2, 3, 4, 5 }, *p;p=a;++*p;printf("%d ", *p);p += 2;printf("%d",
*p);}
A. 2 4
B. 3 4
C. 2 2
D. 2 3
ANSWER: D
char *ptr;char myString[] = "abcdefg";ptr = myString;ptr += 5;what string does p
tr point to in the sample code above?
A. fg
B. efg
C. defg
D. cdefg
ANSWER: A
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: A
What is the output of this C code?int *f();int main(){int *p = f();printf("%d\n"
, *p);}int *f(){int *j = (int*)malloc(sizeof(int));*j = 10;return j;}
A. 10