C Programming Questions and Answers on Arrays of Structures for Freshers

1. The correct syntax to access the member of the ith structure in the array of structures is?

 Assuming: struct temp
    {
        int b;
    }s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
Answer: d
2. Comment on the output of this C code?
  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.         int b;
  6.         int c;
  7.     };
  8.     main()
  9.     {
  10.         struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
  11.     }
a) No Compile time error, generates an array of structure of size 3
b) No Compile time error, generates an array of structure of size 9
c) Compile time error, illegal declaration of a multidimensional array
d) Compile time error, illegal assignment to members of structure
Answer: a
3. Which of the following uses structure?

a) Array of structures
b) Linked Lists
c) Binary Tree
d) All of the mentioned
Answer: d
4. What is the correct syntax to declare a function foo() which receives an array of structure in     function?

a) void foo(struct *var);
b) void foo(struct *var[]);
c) void foo(struct var);
d) none of the mentioned
Answer: a
5. What is the output of this C code?
    (Assuming size of int be 4)

  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.         int b;
  6.         int c;
  7.     } p[] = {0};
  8.     main()
  9.     {
  10.         printf("%d", sizeof(p));
  11.     }
a) 4
b) 12
c) 16
d) Can’t be estimated due to ambigous initialization of array
Answer: b
6. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s[2];
  7.     void main()
  8.     {
  9.         s[0].name = "alan";
  10.         s[1] = s[0];
  11.         printf("%s%s", s[0].name, s[1].name);
  12.         s[1].name = "turing";
  13.         printf("%s%s", s[0].name, s[1].name);
  14.     }
a) alan alan alan turing
b) alan alan turing turing
c) alan turing alan turing
d) run time error
Answer: a
7. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student s[2], r[2];
  7.     void main()
  8.     {
  9.         s[0].name = "alan";
  10.         s[1] = s[0];
  11.         r = s;
  12.         printf("%s%s", r[0].name, r[1].name);
  13.     }
a) alan alan
b) Compile time error
c) Varies
d) Nothing
Answer: b
8. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     void main()
  7.     {
  8.         struct student s[2], r[2];
  9.         s[1] = s[0] = "alan";
  10.         printf("%s%s", s[0].name, s[1].name);
  11.     }
a) alan alan
b) Nothing
c) Compile time error
d) Varies
Answer: c
9. What is the output of this C code?
  1.     #include 
  2.     struct student
  3.     {
  4.     };
  5.     void main()
  6.     {
  7.         struct student s[2];
  8.         printf("%d", sizeof(s));
  9.     }
a) 2
b) 4
c) 8
d) 0
Answer: d
10. What is the output of this C code?
  1.     #include 
  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
Answer: b
11. What is the output of this C code?
  1.     #include 
  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->x);
  16.     }
a) 1
b) 2
c) 3
d) Compile time error
Answer: a
12. What is the output of this C code?
  1.     #include 
  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.     }
a) 1 2
b) 2 2
c) Compile time error
d) Undefined behaviour
Answer: b
13. What is the output of this C code?
  1.     #include 
  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
Answer: a
14. What is the output of this C code?
  1.     #include 
  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
Answer: c
15    #include
  1.     struct point
  2.     {
  3.         int x;
  4.         int y;
  5.     };
  6.     void foo(struct point*);
  7.     int main()
  8.     {
  9.         struct point p1[] = {1, 2, 3, 4, 5};
  10.         foo(p1);
  11.     }
  12.     void foo(struct point p[])
  13.     {
  14.         printf("%d %d\n", p->x, (p + 2).y);
  15.     }
a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) Undefined behaviour
Answer: a
16. What is the output of this C code?
  1.     #include 
  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
Answer: b
17. What is the output of this C code?
  1.     #include 
  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
Answer: d

Related

Multiple Choice Questions 1683891822787023817

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item