C Programming Questions and Answers on Typedef keyword for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_29.html
1. What is the output of this C code?
#include
typedef struct student
{
char *a;
}stu;
void main()
{
struct stu s;
s.a = "hi";
printf("%s", s.a);
}
a) Compile time error
b) Varies
c) hi
d) h
b) Varies
c) hi
d) h
Answer: a
2. What is the output of this C code?
#include
typedef struct student
{
char *a;
}stu;
void main()
{
struct student s;
s.a = "hey";
printf("%s", s.a);
}
a) Compile time error
b) Varies
c) he
d) hey
b) Varies
c) he
d) hey
Answer: d
3. What is the output of this C code?
#include
typedef int integer;
int main()
{
int i = 10, *ptr;
float f = 20;
integer j = i;
ptr = &j;
printf("%d\n", *ptr);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) Depends on the standard
d) 10
b) Undefined behaviour
c) Depends on the standard
d) 10
Answer: d
4. What is the output of this C code?
#include
int (*(x()))[2];
typedef int (*(*ptr)())[2] ptrfoo;
int main()
{
ptrfoo ptr1;
ptr1 = x;
ptr1();
return 0;
}
int (*(x()))[2]
{
int (*ary)[2] = malloc(sizeof*ary);
return &ary;
}
a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard
b) Nothing
c) Undefined behaviour
d) Depends on the standard
Answer: a
5. What is the output of this C code?
#include
int *(*(x()))[2];
typedef int **(*ptrfoo)())[2];
int main()
{
ptrfoo ptr1;
ptr1 = x;
ptr1();
return 0;
}
int *(*(x()))[2]
{
int (*ary)[2] = malloc(sizeof * ary);
return &ary;
}
a) Compile time error
b) Nothing
c) Undefined behaviour
d) Depends on the standard
b) Nothing
c) Undefined behaviour
d) Depends on the standard
Answer: b
6. What is the output of this C code?
#include
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}
a) Compile time error
b) 1
c) 0
d) Depends on the standard
b) 1
c) 0
d) Depends on the standard
Answer: a
7. What is the output of this C code?
#include
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}
a) Compile time error
b) 1
c) 0
d) Depends on the standard
b) 1
c) 0
d) Depends on the standard
Answer: a
8. What is the output of this C code?
#include
typedef struct p
{
int x, y;
}k;
int main()
{
struct p p = {1, 2};
k k1 = p;
printf("%d\n", k1.x);
}
a) Compile time error
b) 1
c) 0
d) Depends on the standard
b) 1
c) 0
d) Depends on the standard
Answer: b
9. The correct syntax to use typedef for struct is.
a) typedef struct temp
{
int a;
}TEMP;
b) typedef struct
{
int a;
}TEMP;
c) struct temp
{
int a;
};
typedef struct temp TEMP;
d) All of the mentioned
Answer: d
10. For the following expression to work, which option should be selected.
string p = “HELLO”;
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;
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?
#include
typedef struct student
{
char *a;
}stu;
void main()
{
stu s;
s.a = "hi";
printf("%s", s.a);
}s
a) Compile time error
b) Varies
c) hi
d) h
b) Varies
c) hi
d) h
Answer: a