This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Structures and Functions – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct point p1 = {1};
if(p == p1)
printf("equal\n");
else
printf("not equal\n");
}
a) Compile time error
b) equal
c) depends on the standard
d) not equal
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
struct notpoint
{
int x;
int y;
};
struct point foo();
int main()
{
struct point p = {1};
struct notpoint p1 = {2, 3};
p1 = foo();
printf("%d\n", p1.x);
}
struct point foo()
{
struct point temp = {1, 2};
return temp;
}
a) Compile time error
b) 1
c) 2
d) Undefined behaviour
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
struct notpoint
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct notpoint p1 = p;
printf("%d\n", p1.x);
}
a) Compile time error
b) 1
c) 0
d) Undefined
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
struct notpoint
{
int x;
int y;
};
void foo(struct point);
int main()
{
struct notpoint p1 = {1, 2};
foo(p1);
}
void foo(struct point p)
{
printf("%d\n", p.x);
}
a) Compile time error
b) 1
c) 0
d) Undefined
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1 = {1, 2};
foo(&p1);
}
void foo(struct point *p)
{
printf("%d\n", *p.x++);
}
a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1 = {1, 2};
foo(&p1);
}
void foo(struct point *p)
{
printf("%d\n", *p->x++);
}
a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
struct student fun(void)
{
struct student
{
char *name;
};
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s", m.name);
}
a) Compile time error
b) alan
c) Nothing
d) Varies
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s", m.name);
}
a) Nothing
b) alan
c) Run time error
d) Varies
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 Computer Science MCQs
- Check Computer Science Books
- Practice BCA MCQs
- Check C Books
- Apply for C Internship