- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to print employee details using Structure
Here, we are given a structure containing details of employees. Our task is to create a C program to program to print employee details using structure.
The details of the employee that are in the structure are name, age, phone number, salary, and our program will print these details.
The details of the employees are pre-declared in the program and we will one by one print all the values. For this, we will create a function that will access the object of the structure and then print all the members of the structure using this object.
C Program to print employee details using structure
// C Program to print employee details using structure −
Example
#include <iostream> using namespace std; struct employee { int empId; string name; int age; string phone_number; int salary; }; void displayDeitals(struct employee emp[], int n) { cout<<"
--- Employee "<<n+1<<" ----
"; cout<<"Employee ID: "<<emp[n].empId<<endl; cout<<"Employee name: "<<emp[n].name<<endl; cout<<"Employee age:"<<emp[n].age<<endl; cout<<"Employee phone number: "<<emp[n].phone_number<<endl; cout<<"Employee salary : "<<emp[n].salary<<endl; } int main() { int n = 3; struct employee emp[4]; emp[0].empId = 0121; emp[0].name = "Nupur"; emp[0].age = 22; emp[0].phone_number = "942135439"; emp[0].salary = 100000; emp[1].empId = 0322; emp[1].name = "Ramesh"; emp[1].age = 41; emp[1].phone_number = "908564363"; emp[1].salary = 50000; emp[2].empId = 023; emp[2].name = "Yash"; emp[2].age = 45; emp[2].phone_number = "943299231"; emp[2].salary = 250000; emp[3].empId = 0112; emp[3].name = "Zarin"; emp[3].age = 35; emp[3].phone_number = "796892522"; emp[3].salary = 300000; for(int i= 0; i<=n; i++) displayDeitals(emp, i); return 0; }
Output
--- Employee 1 ---- Employee ID: 81 Employee name: Nupur Employee age: 22 Employee phone number: 942135439 Employee salary: 100000 --- Employee 2 ---- Employee ID: 210 Employee name: Ramesh Employee age: 41 Employee phone number: 908564363 Employee salary: 50000 --- Employee 3 ---- Employee ID: 19 Employee name: Yash Employee age: 45 Employee phone number: 943299231 Employee salary: 250000 --- Employee 4 ---- Employee ID: 74 Employee name: Zarin Employee age: 35 Employee phone number: 796892522 Employee salary: 300000
- Related Articles
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- C++ Program to Store and Display Information Using Structure
- C program to print characters without using format specifiers
- Program to print the longest common substring using C++
- Program to print root to leaf paths without using recursion using C++
- C++ Program Structure
- Write an example program on structure using C language
- C Program to print “Hello World!” without using a semicolon
- Program to print the DFS traversal step-wise using C++
- C program to print number series without using any loop
- C program to print multiplication table by using for Loop
- How to print Floyd’s triangle (of integers) using C program?
- Write a structure in local scope program using C language
- C++ Program to Print “Even” or “Odd” without using conditional statement
- C Program to print “Even” or “Odd” without using Conditional statement

Advertisements