C program to create, declare and initialize structure

In 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.

Explanation

#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 »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.