C MCQ set number 00720

1. 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 m;
  9.         struct student *s = &m;
  10.         s->c = "hello";
  11.         printf("%s", s->c);
  12.     }

a) hello
b) Run time error
c) Nothing
d) Depends on compiler

Answer

Answer: a [Reason:] None.

2. 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;
  9.         s->c = "hello";
  10.         printf("%s", s->c);
  11.     }

a) hello
b) Segmentation fault
c) Run time error
d) Nothing

Answer

Answer: b [Reason:] None.

3. 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 m;
  9.         struct student *s = &m;
  10.         s->c = "hello";
  11.         printf("%s", m.c);
  12.     }

a) Run time error
b) Nothing
c) hello
d) Varies

Answer

Answer: c [Reason:] None.

4. 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 m;
  9.         struct student *s = &m;
  10.         (*s).c = "hello";
  11.         printf("%s", m.c);
  12.     }

a) Run time error
b) Nothing
c) Varies
d) hello

Answer

Answer: d [Reason:] None.

5. 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 n;
  9.         struct student *s = &n;
  10.         (*s).c = "hello";
  11.         printf("%pn%pn", s, &n);
  12.     }

a) Different address
b) Run time error
c) Nothing
d) Same address

Answer

Answer: d [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x[2];
  5.     };
  6.     struct q
  7.     {
  8.         int *x;
  9.     };
  10.     int main()
  11.     {
  12.         struct p p1 = {1, 2};
  13.         struct q *ptr1;
  14.         ptr1->x = (struct q*)&p1.x;
  15.         printf("%dn", ptr1->x[1]);
  16.     }

a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1

Answer

Answer: b [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x[2];
  5.     };
  6.     struct q
  7.     {
  8.         int *x;
  9.     };
  10.     int main()
  11.     {
  12.         struct p p1 = {1, 2};
  13.         struct q *ptr1 = (struct q*)&p1;
  14.         ptr1->x = (struct q*)&p1.x;
  15.         printf("%dn", ptr1->x[0]);
  16.     }

a) Compile time error
b) Undefined behaviour
c) Segmentation fault/code crash
d) 1

Answer

Answer: b [Reason:] None.

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 2, 3, 4, 5, 6};
  10.         struct p *ptr1 = p1;
  11.         printf("%d %dn", ptr1->x, (ptr1 + 2)->x);
  12.     }

a) 1 5
b) 1 3
c) Compile time error
d) 1 4

Answer

Answer: a [Reason:] None.

9. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main(){
  8.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  9.         struct p *ptr1 = p1;
  10.         int x = (sizeof(p1) / sizeof(struct p));
  11.         printf("%d %dn", ptr1->x, (ptr1 + x - 1)->x);
  12.     }

a) Compile time error
b) Undefined behaviour
c) 1 3
d) 1 5

Answer

Answer: d [Reason:] None.

Total Views: 7

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.

How would you like to contact us?

Contact us

phone email icon
phone email icon
Leave your phone email and messgae. We will call you back soon!
We received your message! We will contact you soon.
Error sending callback request! Please try again!
Write a email to us!
Email sent! We will contact you soon.
Error sending email! Please try again!