C Programming Questions and Answers – Typedefs – 2

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

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

1. Which is the correct syntax to use typedef for struct?
a)

    typedef struct temp
    {
        int a;
    }TEMP;

b)

advertisement
advertisement
    typedef struct
    {
        int a;
     }TEMP;

c)

Note: Join free Sanfoundry classes at Telegram or Youtube
    struct temp
    {
        int a;
    };
    typedef struct temp TEMP;

d) All of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

2. Which option should be selected to work the following C expression?

advertisement
string p = "HELLO";

a) typedef char [] string;
b) typedef char *string;
c) typedef char [] string; and typedef char *string;
d) Such expression cannot be generated in C
View Answer

Answer: b
Explanation: None.

3. Which of the given option is the correct method for initialization?

typedef char *string;

a) *string *p = “Hello”;
b) string p = “Hello”;
c) *string p = ‘A’;
d) Not more than one space should be given when using typedef
View Answer

Answer: b
Explanation: None.

4. Which of the following is false about typedef?
a) typedef follow scope rules
b) typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;)
c) You cannot typedef a typedef with other term
d) All of the mentioned
View Answer

Answer: b
Explanation: None.

5. Which of the following may create problem in the typedef program?
a) ;
b) printf/scanf
c) Arithmetic operators
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

6. typedef int (*PFI)(char *, char *)creates ___________
a) type PFI, for pointer to function (of two char * arguments) returning int
b) error
c) type PFI, function (of two char * arguments) returning int
d) type PFI, for pointer
View Answer

Answer: a
Explanation: None.

7. What is typedef declaration?
a) Does not create a new type
b) It merely adds a new name for some existing type
c) Does not create a new type, It merely adds a new name for some existing type
d) None of the mentioned
View Answer

Answer: c
Explanation: None.

8. 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.         stu s;
  9.         s.a = "hi";
  10.         printf("%s", s.a);
  11.     }s

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

Answer: a
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.