Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         char a[5];
  5.     };
  6.     void main()
  7.     {
  8.         struct student s[] = {"hi", "hey"};
  9.         printf("%c", s[0].a[1]);
  10.     }

a) h
b) i
c) e
d) y

View Answer

Answer: b [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *a[3] = {"hello", "this"};
  5.         printf("%s", a[1]);
  6.     }

a) hello
b) Varies
c) this
d) Compile time error

View Answer

Answer: c [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  5.         printf("%d", lookup[3]);
  6.     }

a) 2
b) 4
c) Compile time error
d) 3

View Answer

Answer: d [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
  5.         , {"hellos", "hi's", "hmm"}};
  6.         printf("%s", a[1][1]);
  7.     }

a) her
b) hi
c) Compile time error
d) hi’s

View Answer

Answer: a [Reason:] None.

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         char *name;
  5.         struct p *next;
  6.     };
  7.     struct p *ptrary[10];
  8.     int main()
  9.     {
  10.         struct p p;
  11.         p->name = "xyz";
  12.         p->next = NULL;
  13.         ptrary[0] = &p;
  14.         printf("%sn", p->name);
  15.         return 0;
  16.     }

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

View Answer

Answer: a [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         char *name;
  5.         struct p *next;
  6.     };
  7.     struct p *ptrary[10];
  8.     int main()
  9.     {
  10.         struct p p;
  11.         p.name = "xyz";
  12.         p.next = NULL;
  13.         ptrary[0] = &p;
  14.         printf("%sn", ptrary[0]->name);
  15.         return 0;
  16.     }

a) Compile time error
b) Segmentation fault
c) Undefined behaviour
d) xyz

View Answer

Answer: d [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         char *name;
  5.         struct p *next;
  6.     };
  7.     struct p *ptrary[10];
  8.     int main()
  9.     {
  10.         struct p p, q;
  11.         p.name = "xyz";
  12.         p.next = NULL;
  13.         ptrary[0] = &p;
  14.         strcpy(q.name, p.name);
  15.         ptrary[1] = &q;
  16.         printf("%sn", ptrary[1]->name);
  17.         return 0;
  18.     }

a) Compile time error
b) Segmentation fault/code crash
c) Depends on the compiler
d) xyz

View Answer

Answer: b [Reason:] None.

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         struct p
  5.         {
  6.             char *name;
  7.             struct p *next;
  8.         };
  9.         struct p p, q;
  10.         p.name = "xyz";
  11.         p.next = NULL;
  12.         ptrary[0] = &p;
  13.         strcpy(q.name, p.name);
  14.         ptrary[1] = &q;
  15.         printf("%sn", ptrary[1]->name);
  16.         return 0;
  17.     }

a) Compile time error
b) Depends on the compiler.
c) Undefined behaviour
d) xyz

View Answer

Answer: c [Reason:] None.