C Programming Questions and Answers on Typedef keyword for Freshers

1. What is the output of this 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
2. What is the output of this 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
3. What is the output of this 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("%d\n", *ptr);
  10.         return 0;
  11.     }
a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 10
Answer: d
4. What is the output of this 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
5. What is the output of this 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
6. What is the output of this 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("%d\n", k1.x);
  10.     }
a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: a
7. What is the output of this 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("%d\n", k1.x);
  10.     }
a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: a
8. What is the output of this 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("%d\n", k1.x);
  11.     }
a) Compile time error
b) 1
c) 0
d) Depends on the standard
Answer: b
9. The correct syntax to use typedef for struct is.
  1. a) typedef struct temp
  2.     {
  3.         int a;
  4.     }TEMP;
  5. b) typedef struct
  6.     {
  7.         int a;
  8.      }TEMP;
  9. c) struct temp
  10.     {
  11.         int a;
  12.     };
  13.     typedef struct temp TEMP;
  14. d) All of the mentioned

Answer: d
 
10. For the following expression to work, which option should be selected.
    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
Answer: b
11. 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
Answer: b
12. 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
Answer: b
13. typedef which of the following may create problem in the program

a) ;
b) printf/scanf
c) Arithmetic operators
d) All of the mentioned
Answer: d
14. 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
Answer: a
15. 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
Answer: c
16. What is the output of this C code?
  1.     #include 
  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
Answer: a

Related

CSS Multiple Choice Questions & Answers on Style Inclusion Methods for Freshers

1. Which of the following tag is used to linked information should be placed inside? a) <head> b) <html> c) <div> d) <body> Answer: a    2. Whi...

C Programming Questions and Answers on Precedence and Order of Evaluation – 1 for Freshers

1. Which of the following operators has an associativity from Right to Left? a) <=b) <<c) ==d) += Answer: d 2. Which operators of the following have same precedence? P. "!="...

Java Multiple Choice Questions & Answers on Class Fundamentals & Declaring objects for Freshers

1. What is the stored in the object obj in following lines of code?box obj; a) Memory address of allocated memory of object.b) NULLc) Any arbitrary pointerd) Garbage Answer: b Explanation: Memory...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item