C MCQ set number 00707

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("equaln");
  13.         else
  14.             printf("not equaln");
  15.     }

a) Compile time error
b) equal
c) depends on the standard
d) not equal

Answer

Answer: a [Reason:] None.

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("%dn", 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

Answer

Answer: a [Reason:] None.

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("%dn", p1.x);
  17.     }

a) Compile time error
b) 1
c) 0
d) Undefined

Answer

Answer: a [Reason:] None.

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("%dn", p.x);
  21.     }

a) Compile time error
b) 1
c) 0
d) Undefined

Answer

Answer: a [Reason:] None.

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("%dn", *p.x++);
  16.     }

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

Answer

Answer: a [Reason:] None.

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("%dn", *p->x++);
  16.     }

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

Answer

Answer: a [Reason:] None.

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

Answer

Answer: a [Reason:] None.

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

Answer

Answer: b [Reason:] None.

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.