ADVERTISEMENT
ADVERTISEMENT

C program to create, declare and initialize structure

n this program, we will learn how to declare a structure with different types of variables, declare and initialization of structure variable? Here we are not reading values from keyboard; we are assigning the values to the structure members at the time of structure variable declaration.

#include <stdio.h>

/*structure declaration*/
struct employee{
	char name[30];
	int empId;
	float salary;
};

int main()
{
	/*declare and initialization of structure variable*/
	struct employee emp={"Mike",1120,76909.00f};
	
	printf("\n Name: %s"	,emp.name);
	printf("\n Id: %d"		,emp.empId);
	printf("\n Salary: %f\n",emp.salary);
	return 0;
}

Output

 Name: Mike 
 Id: 1120 
 Salary: 76909.000000

C Structure & Union Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.