C Programming Questions and Answers – Table Lookup – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Table Lookup – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. What will be the output of the following 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
Explanation: None.
advertisement
advertisement

2. What will be the output of the following C code?

advertisement
  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
Explanation: None.
advertisement

3. What will be the output of the following 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
Explanation: None.
advertisement

4. What will be the output of the following 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
Explanation: None.

5. What will be the output of the following 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("%s\n", p->name);
  15.         return 0;
  16.     }

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

Answer: a
Explanation: None.

6. What will be the output of the following 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("%s\n", ptrary[0]->name);
  15.         return 0;
  16.     }

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

Answer: d
Explanation: None.

7. What will be the output of the following 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("%s\n", 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
Explanation: None.

8. What will be the output of the following 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("%s\n", 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
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.