mcq on pointers in C language,interview and multiple choice questions on pointers in C

Q5.What is the output of the following code snippet in C?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr + 2));
a) 2
b) 3
c) 5
d) Error
Answer: b) 3


Q6.What is the output of the following code snippet is ?
int a = 5, b = 10;
int *ptr1 = &a;
int *ptr2 = &b;
*ptr1 = *ptr2;
printf("%d", a);
a) 5
b) 10
c) 15
d) Error
Answer: b) 10


Q7.What is the output of the following program code in c?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr++));
a) 1
b) 2
c) 3
d) Error
Answer: a) 1


Q8.What is the output of the following C program code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[3];
printf("%d", *ptr);
a) 1
b) 2
c) 4
d) 5
Answer: c) 4


Q9.How do you declare a pointer to a function that takes no arguments and returns an integer in C?
a) int (*ptr)();
b) int *ptr();
c) int *ptr(void);
d) int (*ptr)(void);
Answer: d) int (*ptr)(void);


Q10.What is the output of the following C code ?
int a = 5;
int *ptr = &a;
int **ptr2 = &ptr;
printf("%d", **ptr2);
a) 5
b) 10
c) Error
d) Compile-time error
Answer: a) 5 .


Q11.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *ptr + 2);
a) 1
b) 2
c) 3
d) 5
Answer: c) 3


Q12.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[1];
printf("%d", *ptr - 1);
a) 0
b) 1
c) 2
d) 3
Answer: b) 1


Q13.What is the output of the following C code ?
int x = 5;
int *ptr = &x;
*ptr += 2;
printf("%d", x);
a) 3
b) 5
c) 7
d) 10
Answer: c) 7


Q14.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 2;
printf("%d", *ptr);
a) 1
b) 2
c) 3
d) 4
Answer: c) 3


Q15.What is the output of the following C code?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 3;
printf("%d", *ptr - 2);
a) 1
b) 2
c) 3
d) 4
Answer: b) 2


Q16.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr)++);
a) 1
b) 2
c) 3
d) 4
Answer: a) 1


Q17.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[2];
printf("%d", *ptr++);
a) 1
b) 2
c) 3
d) 4
Answer:c ) 3


Q18.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *(ptr += 2));
a) 1
b) 2
c) 3
d) 4
Answer: c) 3


Q19.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 1;
printf("%d", *(ptr--));
a) 1
b) 2
c) 3
d) 4
Answer: b) 2


Q20.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[4];
printf("%d", *ptr);
a) 1
b) 2
c) 5
d) 6
Answer: c) 5


Q21.What is the output of the following C code ?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[0];
printf("%d", *(ptr + 4));
a) 1
b) 2
c) 4
d) 5
Answer: d) 5


Q22.What is the output of the following C code ?
int a = 5, b = 10;
int *ptr1 = &a;
int *ptr2 = &b;
int temp = *ptr1;
*ptr1 = *ptr2;
*ptr2 = temp;
printf("%d", a);
a) 5
b) 10
c) 15
d) Error
Answer: b) 10


Q23.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[0];
printf("%d", *(ptr + 1) - *ptr);
a) 0
b) 1
c) 2
d) 3
Answer: b) 1


Q24.What is the output of the following program code?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 3;
printf("%d", *ptr - *(ptr - 1));
a) 0
b) 1
c) 2
d) 3
Answer: b) 1


Q25.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
printf("%d", *++ptr - *ptr);
a) 0
b) 1
c) 2
d) 3
Answer: b) 1


Q26.What is the output of the following C code snippet?
int a = 5;
int *ptr = &a;
*ptr--;
printf("%d", a);
a) 5
b) 4
c) 6
d) 0
Answer: a) 5


Q27.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 2;
printf("%d", *(ptr--));
a) 1
b) 2
c) 3
d) 4
Answer: c) 3


Q28.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr + 2;
printf("%d", *ptr++);
a) 1
b) 2
c) 3
d) 4
Answer: c) 3


Q29.What is the output of the following C code snippet?
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &arr[2];
printf("%d", *ptr--);
a) 1
b) 2
c) 3
d) 4
Answer: c) 3


Q30.What is the output of the following C code snippet?
int x = 5;
int *ptr = &x;
*ptr--;
printf("%d", x);
a) 5
b) 4
c) 6
d) 0
Answer: b) 4



Previous Topic:-->>Structure MCQ. || Next topic:-->>Files MCQ in C.