Structures
- What will be the output of the following C code?
#include <stdio.h>
struct option1
{
int m;
int n;
};
struct option2
{
int m;
int n;
};
struct option1 fun();
int main()
{
struct option1 opt1 = {11};
struct option2 opt2 = {21, 31};
opt2 = fun();
printf("%d\n", opt2.m);
}
struct option1 fun()
{
struct option1 temp = {11, 21};
return temp;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:17:14: error: incompatible types when assigning to type ‘struct option2’ from type ‘struct option1’
opt2 = fun();
- What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *Name;
};
struct Employee fun(void)
{
struct Employee emp1;
emp1.Name = "Prayag";
return emp1;
}
void main()
{
struct Employee emp2 = fun();
emp1.Name = "Ajit";
printf("%s", emp2.Name);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:15:9: error: ‘emp1’ undeclared (first use in this function); did you mean ‘emp2’?
emp1.Name = "Ajit";
^~~~
emp2
main.c:15:9: note: each undeclared identifier is reported only once for each function it appears in
- What will be the output of the following C code?
#include <stdio.h>
struct Calc
{
int m;
int n;
};
int main()
{
struct Calc c = {10};
struct Calc c1 = {11};
if(c == c1)
printf("Equal\n");
else
printf("Not Equal\n");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
- Presence of code like “s.t.b = 100” indicates __________.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Structure
- What will be the output of the following C code?
#include <stdio.h>
struct option1
{
int m;
int n;
};
struct option2
{
int m;
int n;
};
int main()
{
struct option1 opt1 = {10};
struct option2 opt2 = opt1;
printf("%d\n", opt2.m);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:15:31: error: invalid initializer
struct option2 opt2 = opt1;