The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Structures Tricky Questions

In most of the MNC interview questions such as in ZOHO interview question, IVTL Infoview interview questions, Amazon interview questions, GOOGLE interview questions, Infosys interview questions and even in Voonik interview questions, We come across several Tricky C Questions about which 2:5 of the questions are from Structure in c. Solving that kind of tricky C questions is not an easy task for all C programmers. We need more practices to solve it with ease. So we provide 25+ interesting C questions in structure to make your MNC interview very easy.

C Structures Tricky Questions

6. What will be the output of the C program?

#include<stdio.h>
	
struct employee
{
	char *empname;
	int salary;
};
int main()
{
	struct employee e, e1;
	e.empname = "Sridhar";
	e1 = e;
	printf("%s %s", e.empname, e1.empname);
	return 0;
}

A. Garbage value Sridhar

B. Sridhar Garbage value

C. Sridhar Sridhar

D. Compilation Error

x

 

Option: C

Explanation

We can assign structure variable to the another structure variable and it can be accessed.

Answer


7.What will be the output of the C program(assume size of int as 2 bytes)?

#include<stdio.h>
int main()
{
	struct employee 
	{
		int empid[5];
		int salary;
		employee *s;
	}emp;
printf("%d %d", sizeof(employee), sizeof(emp.empid));
return 0;
}

A. 6 2

B. 14 10

C. 8 2

D. 12 10

x

 

Option: B

Explanation

Structure always allocates memory for each of its members. Thats what happens here, an int occupies 2 bytes so empid variable occupies 10 bytes, variable salary occupies 2 bytes and the pointer variable occpies 2 bytes. So the sizeof structure employee occipes 14 bytes and structure member empid occupies 10 bytes.

Answer


8.What will be the output of the C program?

#include<stdio.h>
#include<string.h>
struct player 
{
	char pname[20];
}pl;
char* play(struct player *temp_pl)
{
	strcpy(temp_pl->pname, "kohli");
	return temp_pl->pname;
}
int main()
{
	strcpy(pl.pname, "dhoni");
	printf("%s %s", pl.pname, play(&pl));
	return 0;
}

A. dhoni kohli

B. dhoni dhoni

C. None

D. kohli kohli

x

 

Option: D

Explanation

In the main function the string "dhoni" is copied to the structure member pl.pname using strcpy function(should have a prototype string.h). A function with structure member as a parameter play(&pl) - call by reference method, will be called inside the printf statement. The function is declared as, structure pointer temp_pl as a parameter and char pointer(which returns string) as a return type. Inside that function the string "kohli" is copied to the structure member temp_pl->pname, here temp_pl is the structure(player) variable and pname is the structure(player) member. So the new string is assinged to the structure member. Finally it will prints "kohli kohli".

Answer


9.What will be the output of the C program?

#include<stdio.h>
struct decl 
{
	int n = 100;
}d1;
int main()
{
	printf("%d",d1.n);
	return 0;
}

A. 100

B. Compilation Error

C. 0

D. Garbage value

x

 

Option: B

Explanation

Structure is used to declare a datatype, When we declare datatypes inside structure it does not allocate memory for it. So we can't store any data in a structure member.

Answer


10.What will be the output of the C program?

#include<stdio.h>
struct TeamScore
{
	int wickets;
	int score;
}ts = {2, 325};
struct country
{
	char *name;
}coun = {"India"};
int main()
{
	struct TeamScore tcon = ts;
	printf("%d %s %d", tcon.score, ts.wickets, coun.name);
	return 0;
}

A. 325 2 India

B. 325 2 garbage value

C. copilation error

D. None of the above

x

 

Option: A

Explanation

The above program just prints all structure memeber values.

Answer


Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report