This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Complicated Declarations – 1”.
Pre-requisite for C Complicated Declarations MCQ set: Video Tutorial on C Pointers.
1. What will be the output of the following C code?
#include <stdio.h>
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
no = 8;
printf("%d", no);
}
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
struct student
{
int no;
char name[20];
};
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
a) Run time error
b) Nothing
c) hello
d) Varies
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
struct student
{
int no = 5;
char name[20];
};
void main()
{
struct student s;
s.no = 8;
printf("hello");
}
a) Nothing
b) Compile time error
c) hello
d) Varies
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
struct student
{
int no;
char name[20];
};
void main()
{
student s;
s.name = "hello";
printf("hello");
}
a) Nothing
b) hello
c) Compile time error
d) Varies
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%s", s.name);
}
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
struct student
{
int no;
char name[20];
};
struct student s;
void main()
{
s.no = 8;
printf("%s", s.name);
}
a) Nothing
b) Compile time error
c) Junk
d) 8
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int *((*x)())[2];
x();
printf("after x\n");
}
int *((*x)())[2]
{
int **str;
str = (int*)malloc(sizeof(int)* 2);
return str;
}
a) Compile time error
b) Undefined behaviour
c) After x
d) None of the mentioned
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
void (*(f)())(int, float);
void (*(*x)())(int, float) = f;
void ((*y)(int, float));
void foo(int i, float f);
int main()
{
y = x();
y(1, 2);
}
void (*(f)())(int, float)
{
return foo;
}
void foo(int i, float f)
{
printf("%d %f\n", i, f);
}
a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
View Answer
Explanation: None.
9. What does this declaration say?
int (*(*y)())[2];
a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
d) y is function which returns array of integers
View Answer
Explanation: None.
10. What will be the output of the following C code?
#include <stdio.h>
void (*(f)())(int, float);
typedef void (*(*x)())(int, float);
void foo(int i, float f);
int main()
{
x = f;
x();
}
void (*(f)())(int, float)
{
return foo;
}
void foo(int i, float f)
{
printf("%d %f\n", i, f);
}
a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
View Answer
Explanation: None.
11. What will be the output of the following C code?
#include <stdio.h>
void (*(f)())(int, float);
typedef void (*(*x)())(int, float);
void foo(int i, float f);
int main()
{
x p = f;
p();
}
void (*(f)())(int, float)
{
return foo;
}
void foo(int i, float f)
{
printf("%d %f\n", i, f);
}
a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
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.
- Apply for C Internship
- Check C Books
- Practice BCA MCQs
- Check Computer Science Books
- Watch Advanced C Programming Videos