Pointers - C Questions

Pointers Questions - 1 Pointers Questions - 2 Pointers Questions - 3 Pointers Questions - 4 Pointers Questions - 5 Pointers Questions - 6 Pointers Questions - 7 Pointers Questions - 8

Data Types - C Questions

Data Types Questions - 1 Data Types Questions - 2 Data Types Questions - 3 Data Types Questions - 4 Data Types Questions - 5

Operators - C Questions

Operators Questions - 1 Operators Questions - 2 Operators Questions - 3 Operators Questions - 4 Operators Questions - 5

Structures - C Questions

Structures Questions - 1 Structures Questions - 2 Structures Questions - 3 Structures Questions - 4 Structures Questions - 5

Files - C Questions

Files Questions - 1 Files Questions - 2 Files Questions - 3 Files Questions - 4 Files Questions - 5

printf - C Questions

printf Questions - 1 printf Questions - 2 printf Questions - 3 printf Questions - 4 printf Questions - 5

Variables - C Questions

Variables Questions - 1 Variables Questions - 2 Variables Questions - 3 Variables Questions - 4 Variables Questions - 5

Preprocessor Macros

Preprocessor Macros - 1 Preprocessor Macros - 2 Preprocessor Macros - 3 Preprocessor Macros - 4 Preprocessor Macros - 5

While Loop - C Questions

While Loop Questions - 1 While Loop Questions - 2 While Loop Questions - 3 While Loop Questions - 4 While Loop Questions - 5

for Loop - C Questions

for Loop Questions - 1 for Loop Questions - 2 for Loop Questions - 3 for Loop Questions - 4 for Loop Questions - 5

if else - C Questions

if else Questions - 1 if else Questions - 2 if else Questions - 3 if else Questions - 4 if else Questions - 5

Switch case - C Questions

Switch case Questions - 1 Switch case Questions - 2 Switch case Questions - 3 Switch case Questions - 4 Switch case Questions - 5

Array - C Questions

Array Questions - 1 Array Questions - 2 Array Questions - 3 Array Questions - 4 Array Questions - 5

Functions - C Questions

Functions Questions - 1 Functions Questions - 2 Functions Questions - 3 Functions Questions - 4 Functions Questions - 5

Memory Allocation

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

C Structures Tricky Questions/h1>

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

We to update you