Here is a listing of C question bank on “Complicated Declarations” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
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
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
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
Answer: b
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
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
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int *((*x)())[2];
-
x();
-
printf("after xn");
-
}
-
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
Answer: a
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
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 %fn", i, f);
-
}
a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
Answer: a
Clarification: None.
9. What does this declaration say?
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
Answer: a
Clarification: None.
10. What will be the output of the following C code?
-
#include
-
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 %fn", i, f);
-
}
a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
Answer: a
Clarification: None.
11. What will be the output of the following C code?
-
#include
-
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 %fn", i, f);
-
}
a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
Answer: d
Clarification: None.