C Programming Questions and Answers – Typedefs – 1

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

Pre-requisite for C Typedef MCQ set: Video Tutorial on C Typedef.

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

  1.     #include <stdio.h>
  2.     typedef struct student
  3.     {
  4.         char *a;
  5.     }stu;
  6.     void main()
  7.     {
  8.         struct stu s;
  9.         s.a = "hi";
  10.         printf("%s", s.a);
  11.     }

a) Compile time error
b) Varies
c) hi
d) h
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

Note: Join free Sanfoundry classes at Telegram or Youtube
  1.     #include <stdio.h>
  2.     typedef struct student
  3.     {
  4.         char *a;
  5.     }stu;
  6.     void main()
  7.     {
  8.         struct student s;
  9.         s.a = "hey";
  10.         printf("%s", s.a);
  11.     }

a) Compile time error
b) Varies
c) he
d) hey
View Answer

Answer: d
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     typedef int integer;
  3.     int main()
  4.     {
  5.         int i = 10, *ptr;
  6.         float f = 20;
  7.         integer j = i;
  8.         ptr = &j;
  9.         printf("%d\n", *ptr);
  10.         return 0;
  11.     }

a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 10
View Answer

Answer: d
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     int (*(x()))[2];
  3.     typedef int (*(*ptr)())[2] ptrfoo;
  4.     int main()
  5.     {
  6.         ptrfoo ptr1;
  7.         ptr1 = x;
  8.         ptr1();
  9.         return 0;
  10.     }
  11.     int (*(x()))[2]
  12.     {
  13.         int (*ary)[2] = malloc(sizeof*ary);
  14.         return &ary;
  15.     }

a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int *(*(x()))[2];
  3.     typedef int **(*ptrfoo)())[2];
  4.     int main()
  5.     {
  6.         ptrfoo ptr1;
  7.         ptr1 = x;
  8.         ptr1();
  9.         return 0;
  10.     }
  11.     int *(*(x()))[2]
  12.     {
  13.         int (*ary)[2] = malloc(sizeof * ary);
  14.         return &ary;
  15.     }

a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     };
  6.     int main()
  7.     {
  8.         p k1 = {1, 2};
  9.         printf("%d\n", k1.x);
  10.     }

a) Compile time error
b) 1
c) 0
d) Depends on the standard
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     }k = {1, 2};
  6.     int main()
  7.     {
  8.         p k1 = k;
  9.         printf("%d\n", k1.x);
  10.     }

a) Compile time error
b) 1
c) 0
d) Depends on the standard
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     }k;
  6.     int main()
  7.     {
  8.         struct p p = {1, 2};
  9.         k k1 = p;
  10.         printf("%d\n", k1.x);
  11.     }

a) Compile time error
b) 1
c) 0
d) Depends on the standard
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.