This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Structures and Functions – 1”.
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 student
{
char *name;
};
struct student s;
struct student fun(void)
{
s.name = "newton";
printf("%s\n", s.name);
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s\n", m.name);
m.name = "turing";
printf("%s\n", s.name);
}
a) newton alan alan
b) alan newton alan
c) alan alan newton
d) compile time error
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}
a) Compile time error
b) Nothing
c) Junk values
d) st st
View Answer
Explanation: None.
3. Which of the following return-type cannot be used for a function in C?
a) char *
b) struct
c) void
d) none of the mentioned
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
struct temp
{
int a;
} s;
void func(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
main()
{
func(s);
printf("%d\t", s.a);
}
a) 10 (Garbage Value)
b) 0 10
c) 10 0
d) (Garbage Value) 10
View Answer
Explanation: None.
5. Which of the following is not possible under any scenario?
a) s1 = &s2;
b) s1 = s2;
c) (*s1).number = 10;
d) None of the mentioned
View Answer
Explanation: None.
6. Which of the following operation is illegal in structures?
a) Typecasting of structure
b) Pointer to a variable of the same structure
c) Dynamic allocation of memory for structure
d) All of the mentioned
View Answer
Explanation: None.
7. Presence of code like “s.t.b = 10” indicates __________
a) Syntax Error
b) Structure
c) double data type
d) An ordinary variable name
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();
s.name = "turing";
printf("%s", m.name);
}
a) alan
b) Turing
c) Compile time error
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.
- Check C Books
- Apply for C Internship
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos