C Programming Questions and Answers Arrays of Structures
2
Sanfoundrys 1000+ Interview Questions & Answers on C helps anyone preparing for Philips and
other companies C interviews. One should practice these 1000+ interview questions and answers
continuously for 2-3 months to clear Philips interviews on C Programming language.
Here is a listing of C interview questions on Arrays of Structures along with answers,
explanations and/or solutions:
1. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1[] = {1, 2, 3, 4};
11. foo(p1);
12. }
13. void foo(struct point p[])
14. {
15. printf("%d\n", p[1].x);
16. }
a) Compile time error
b) 3
c) 2
d) 1
View Answer
Answer:b
2. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
1. What is the output of this C code?
6. #include <stdio.h>
7. struct point
8. {
9. int x;
10. int y;
11.
12. };
13. void foo(struct point*);
14. int main()
15. {
16. struct point p1[] = {1, 2, 3, 4};
17. foo(p1);
18. }
19. void foo(struct point p[])
20. {
21. printf("%d\n", p->x);
22. }
a) 1
b) 2
c) 3
d) Compile time error
View Answer
Answer:a
3. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1[] = {1, 2, 3, 4};
11. foo(p1);
12. }
13. void foo(struct point p[])
14. {
15. printf("%d %d\n", p->x, ++p->x);
16. }
advertisements
a) 1 2
b) 2 2
c) Compile time error
d) Undefined behaviour
View Answer
Answer:b
4. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. } p[] = {1, 2, 3, 4, 5};
7. void foo(struct point*);
8. int main()
9. {
10. foo(p);
11. }
12. void foo(struct point p[])
13. {
14. printf("%d %d\n", p->x, p[2].y);
15. }
a) 1 0
b) Compile time error
c) 1 somegarbagevalue
d) Undefined behaviour
View Answer
Answer:a
5. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1[] = {1, 2, 3, 4, 5};
11. foo(p1);
12. }
13. void foo(struct point p[])
14. {
15. printf("%d %d\n", p->x, p[3].y);
16. }
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) None of the mentioned
View Answer
Answer:c
6. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1[] = {1, 2, 3, 4, 5};
11. foo(p1);
12. }
13. void foo(struct point p[])
14. {
15. printf("%d %d\n", p->x, (p + 2).y);
16. }
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) Undefined behaviour
View Answer
Answer:a
advertisements
7. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1[] = {1, 2, 3, 4, 5};
11. foo(p1);
12. }
13. void foo(struct point p[])
14. {
15. printf("%d %d\n", p->x, (p + 2)->y);
16. }
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) undefined behaviour
View Answer
Answer:b
8. What is the output of this C code?
1. #include <stdio.h>
2. struct student
3. {
4. char *c;
5. };
6. void main()
7. {
8. struct student s[2];
9. printf("%d", sizeof(s));
10. }
a) 2
b) 4
c) 16
d) 8
View Answer
Answer:d
1. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. int main()
8. {
9. struct point p = {1};
10. struct point p1 = {1};
11. if(p == p1)
12. printf("equal\n");
13. else
14. printf("not equal\n");
15. }
a) Compile time error
b) equal
c) depends on the standard
d) not equal
View Answer
Answer:a
2. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. struct notpoint
8. {
9. int x;
10. int y;
11. };
12. struct point foo();
13. int main()
14. {
15. struct point p = {1};
16. struct notpoint p1 = {2, 3};
17. p1 = foo();
18. printf("%d\n", p1.x);
19. }
20. struct point foo()
21. {
22. struct point temp = {1, 2};
23. return temp;
24. }
a) Compile time error
b) 1
c) 2
d) Undefined behaviour
View Answer
Answer:a
3. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. struct notpoint
8. {
9. int x;
10. int y;
11. };
12. int main()
13. {
14. struct point p = {1};
15. struct notpoint p1 = p;
16. printf("%d\n", p1.x);
17. }
advertisements
a) Compile time error
b) 1
c) 0
d) Undefined
View Answer
Answer:a
4. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. struct notpoint
8. {
9. int x;
10. int y;
11. };
12. void foo(struct point);
13. int main()
14. {
15. struct notpoint p1 = {1, 2};
16. foo(p1);
17. }
18. void foo(struct point p)
19. {
20. printf("%d\n", p.x);
21. }
a) Compile time error
b) 1
c) 0
d) Undefined
View Answer
Answer:a
5. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1 = {1, 2};
11. foo(&p1);
12. }
13. void foo(struct point *p)
14. {
15. printf("%d\n", *p.x++);
16. }
a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
View Answer
Answer:a
6. What is the output of this C code?
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. void foo(struct point*);
8. int main()
9. {
10. struct point p1 = {1, 2};
11. foo(&p1);
12. }
13. void foo(struct point *p)
14. {
15. printf("%d\n", *p->x++);
16. }
a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
View Answer
Answer:a
advertisements
7. What is the output of this C code?
1. #include <stdio.h>
2. struct student fun(void)
3. {
4. struct student
5. {
6. char *name;
7. };
8. struct student s;
9. s.name = "alan";
10. return s;
11. }
12. void main()
13. {
14. struct student m = fun();
15. printf("%s", m.name);
16. }
a) Compile time error
b) alan
c) Nothing
d) Varies
View Answer
Answer:a
8. What is the output of this C code?
1. #include <stdio.h>
2. struct student
3. {
4. char *name;
5. };
6. struct student fun(void)
7. {
8. struct student s;
9. s.name = "alan";
10. return s;
11. }
12. void main()
13. {
14. struct student m = fun();
15. printf("%s", m.name);
16. }
a) Nothing
b) alan
c) Run time error
d) Varies
View Answer
Answer:b
1. What is the output of this C code?
1. #include <stdio.h>
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. no = 8;
11. printf("%d", no);
12. }
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Answer:b
2. Number of bytes in memory taken by the below structure is
1. #include <stdio.h>
2. struct test
3. {
4. int k;
5. char c;
6. };
a) Multiple of integer size
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
View Answer
Answer:b
3. What is the output of this C code?
1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. };
7. int main()
8. {
9. struct p;
10. p.k = 10;
11. printf("%d\n", p.k);
12. }
a) Compile time error
b) 10
c) Undefined behaviour
d) Segmentation fault
View Answer
Answer:a
advertisements
4. What is the output of this C code?
1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. } p;
7. int p = 10;
8. int main()
9. {
10. p.k = 10;
11. printf("%d %d\n", p.k, p);
12. }
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
View Answer
Answer:a
5. What is the output of this C code?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. };
7. int p = 10;
8. int main()
9. {
10. struct p x;
11. x.k = 10;
12. printf("%d %d\n", x.k, p);
13. }
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
View Answer
Answer:b
6. What is the output of this C code?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int p = 10;
9. int main()
10. {
11. struct p x = {1, 97};
12. printf("%f %d\n", x.f, p);
13. }
a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
View Answer
Answer:b
7. What is the output of this C code(according to C99 standard)?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .f = 3, .k = 1};
11. printf("%f\n", x.f);
12. }
advertisements
a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
View Answer
Answer:a
8. What is the output of this C code(according to C99 standard)?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .k = 1, 3};
11. printf("%f \n", x.f);
12. }
a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
View Answer
Answer:b
9. What is the output of this C code(according to C99 standard)?
1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97};
11. printf("%f\n", x.f);
12. }
a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
View Answer
Answer:a
1. What is the output of this C code?
1. #include <stdio.h>
2. union
3. {
4. int x;
5. char y;
6. }p;
7. int main()
8. {
9. p.x = 10;
10. printf("%d\n", sizeof(p));
11. }
a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(int)
View Answer
Answer:d
2. What is the output of this C code?
1. #include <stdio.h>
2. union
3. {
4. int x;
5. char y;
6. }p;
7. int main()
8. {
9. p.y = 60;
10. printf("%d\n", sizeof(p));
11. }
a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(char)
View Answer
Answer:c
3. What is the output of this C code?
1. #include <stdio.h>
2. union p
3. {
4. int x;
5. char y;
6. };
7. int main()
8. {
9. union p p, b;
10. p.y = 60;
11. b.x = 12;
12. printf("%d\n", p.y);
13. }
advertisements
a) Compile time error
b) Depends on the compiler
c) 60
d) Undefined behaviour
View Answer
Answer:c
4. What is the output of this C code?
1. #include <stdio.h>
2. union p
3. {
4. int x;
5. char y;
6. }k = {1, 97};
7. int main()
8. {
9. printf("%d\n", k.y);
10. }
a) Compile time error
b) 97
c) a
d) 1
View Answer
Answer:d
5. What is the output of this C code?
1. #include <stdio.h>
2. union p
3. {
4. int x;
5. char y;
6. }k = {.y = 97};
7. int main()
8. {
9. printf("%d\n", k.y);
10. }
a) Compile time error
b) 97
c) a
d) Depends on the standard
View Answer
Answer:b
6. What is the output of this C code?
1. #include <stdio.h>
2. union p
3. {
4. int x;
5. float y;
6. };
7. int main()
8. {
9. union p p, b;
10. p.x = 10;
11. printf("%f\n", p.y);
12. }
advertisements
a) Compile time error
b) Implementation dependent
C) 10.000000
d) 0.000000
View Answer
Answer:b
7. Which of the following share a similarity in syntax?
1. Union, 2. Structure, 3. Arrays and 4. Pointers
a) 3 and 4
b) 1 and 2
c) 1 and 3
d) 1, 3 and 4
View Answer
Answer:b
8. What is the output of this C code?
1. #include <stdio.h>
2. union utemp
3. {
4. int a;
5. double b;
6. char c;
7. }u;
8. int main()
9. {
10. u.c = 'A';
11. u.a = 1;
12. printf("%d", sizeof(u));
13. }
The output will be: (Assuming size of char = 1, int = 4, double = 8)
a) 1
b) 4
c) 8
d) 13
View Answer
Answer:c