C Programming Questions and Answers – Complicated Declarations – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Complicated Declarations – 2”.

Pre-requisite for C Complicated Declarations MCQ set: Video Tutorial on C Pointers.

1. Read the following expression?

void (*ptr)(int);

a) ptr is pointer to int that converts its type to void
b) ptr is pointer to function passing int returning void
c) ptr is pointer to void that converts its type to int
d) ptr is pointer to function passing void returning int
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

2. Which of the following expression is true for the following C statement?

Note: Join free Sanfoundry classes at Telegram or Youtube
ptr is array with 3 elements of pointer to function returning pointer of int

a) int **ptr[3]();
b) int *(*ptr[3])();
c) int (*(*ptr[3])());
d) None of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

3. What makes the following declaration denote?

int **ptr;

a) ptr is a function pointer that returns pointer to int type
b) ptr is a pointer to an int pointer
c) ptr is a pointer to pointer to type int
d) none of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

4. What makes the following declaration denote?

char *str[5];

a) str is an array of 5 element pointer to type char
b) str is a pointer to an array of 5 elements
c) str is a function pointer of 5 elements returning char
d) none of the mentioned
View Answer

Answer: a
Explanation: None.

5. Comment on the following declaration.

    int (*ptr)(); // i)
    char *ptr[]; // ii)

a) Both i) and ii) and cannot exist due to same name
b) i) is legal, ii) is illegal
c) i) is illegal, ii) is legal
d) Both i) and ii) will work legal and flawlessly
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     }
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Compile time error
b) Nothing
c) hello
d) Varies
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%d", s.no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer

Answer: d
Explanation: None.

10. Is the below declaration legal?

int* ((*x)())[2];

a) True
b) False
c) Undefined behaviour
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.

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.