250+ TOP MCQs on Typedefs and Answers

C programming questions on “Typedefs”. One shall practice these questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming questions on “Typedefs” along with answers, explanations and/or solutions:

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

  1.     #include 
  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
Answer: a
Clarification: None.

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

  1.     #include 
  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
Answer: d
Clarification: None.

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

  1.     #include 
  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("%dn", *ptr);
  10.         return 0;
  11.     }

a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 10
Answer: d
Clarification: None.

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

  1.     #include 
  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
Answer: a
Clarification: None.

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

  1.     #include 
  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
Answer: b
Clarification: None.

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

  1.     #include 
  2.     typedef struct p
  3.     {
  4.         int x, y;
  5.     };
  6.     int main()
  7.     {
  8.         p k1 = {1, 2};
  9.         printf("%dn", k1.x);
  10.     }

a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: a
Clarification: None.

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

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

a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: a
Clarification: None.

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

  1.     #include 
  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("%dn", k1.x);
  11.     }

a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: b
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *