The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
In most of the MNC interview questions such as in ZOHO interview question, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, We come across several Tricky C Questions about which 2:5 of the questions are from Array in c. Solving that kind of tricky C questions is not an easy task for all C programmers. We need more practices to solve it with ease. So we provide 25+ interesting C questions in Array to make your MNC interview very easy.
11. What will be the output of the C program?
#include<stdio.h> int main() { int i = 0; printf("Hello"); char s[4] = {'\b', '\t', '\r', '\n'}; for(i = 0;i<4;i++){ printf("%c", s[i]); } return 0; }
Option: C
Hello is printed followed by \b\t\r\n.
i.e) Hello\b\t\r\n.
i.e) Hell\t\r\n.
i.e) Hell \r\n.
i.e) Hell\n.
i.e) Hell is Outputted.
12. What will be the output of the C program?
#include<stdio.h> int main() { static int a[ ] = {0, 1, 2, 3, 4}; int *p[ ] = {a, a + 1, a + 2, a + 3, a + 4}; int **ptr = p; ++*ptr; printf("%d %d %d", ptr - p, *ptr - a, **ptr); return 0; }
Option: A
*p[] is a pointer array variable which holds the all 5 addressess of a value in static integer array a[].
Address of 0 in a[] array is 4210692
Then a value of a in *p[] is 4210692 i.e) address of 0 in a[]
Now, the address of a in *p[] array is 2293416.
**ptr = p;
**ptr = 0;
**ptr = p;
**ptr= address of first element in p[];
We know that **ptr == *(*ptr)
then, *(*ptr) == *(*(address of first element in p[]))
*(*(address of first element in p[])) == *(value of first element in an array p[])
*(value of first element in an array p[]) == *(address of first element in an array a[])
*(address of first element in an array a[]) == value of first element in an array a[];
that is 0
we know that ++(*ptr) == ++(*(address of first element in p[]))
++(*(address of first element in p[])) == ++(value of first element in an array p[])
++(value of first element in an array p[]) == ++(address of first element in a[] which is address of 0)
++(address of first element in a[] which is address of 0) == address of second element in a[] which is address of 1
printf ("%d %d %d", ptr-p, *ptr-a, **ptr);
printf ("%d %d %d",2293416-2293416, *ptr-a, **ptr);
printf("%d %d %d", 0/(sizeof (int)), 4210696-4210692, **ptr);
printf("%d %d %d", 0, 4/(sizeof (int)), **ptr);
printf("%d %d %d", 0, 4/4, **ptr);
printf("%d %d %d", 0, 1, **ptr);
printf("%d %d %d", 0, 1, 1);
Thus 0 1 1 is outputted.
13. What will be the output of the C program?
#include<stdio.h> int main() { int i = 0; char s[4] = {'\0', '\0', '\0', '\0'}; for(i = 0;i<4;i++) { printf("%c", s[i]); } return 0; }
Option: C
\0 = NULL. Thus compiler prints nothing.
14. What will be the output of the C program?
#include<stdio.h> int main() { char s[] = {'a', 'b', 'c', '\n', 'c', '\0'}; char *p, *str, *str1; p = &s[3]; str = p; str1 = s; printf("%d", ++*p + ++*str1-32); return 0; }
Option: B
p = &s[3].
i.e) p = address of '\n';
str = p;
i.e) str = address of p;
str1 = s;
str1 = address of 'a';
printf ("%d", ++*p + ++*str1 - 32);
i.e) printf("%d", ++\n + a -32);
i.e) printf("%d", 12 + 97 -32);
i.e) printf("%d", 12 + 65);
i.e) printf("%d", 77);
Thus 77 is outputted.
15. What will be the output of the C program?
#include<stdio.h> int main() { int i = 0; printf("Hello"); char s[4] = {'\b', '\r', '\t', '\n'}; for(i = 0;i<4;i++) { printf("%c", s[i]); } return 0; }
Option: C
Hello is printed followed by \b\r\t\n.
i.e) Hello\b\r\t\n.
i.e) Hell\r\t\n.
i.e) \t\n.
i.e) \n.
i.e) is Outputted.ie(8 space is outputted)
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019