This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Typedefs – 1”.
Pre-requisite for C Typedef MCQ set: Video Tutorial on C Typedef.
1. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
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
View Answer
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.
- Practice BCA MCQs
- Apply for C Internship
- Watch Advanced C Programming Videos
- Apply for Computer Science Internship
- Check Computer Science Books