Reference Material II
Reference Material II
// driver code
int main()
{
struct parent var1 = { 25, 195, 'A' };
• e1.doj.dd
• e1.doj.mm
• e1.doj.yyyy
#include <stdio.h>
#include <string.h>
struct Organisation
{
char organisation_name[20];
char org_number[20];
struct Employee
{
int employee_id;
char name[20];
int salary;
} emp;
};
// Driver code
int main()
{
struct Organisation org;
// Print the size of organisation
// structure
printf("The size of structure organisation : %ld\n",
sizeof(org));
org.emp.employee_id = 101;
strcpy(org.emp.name, "Robert");
org.emp.salary = 400000;
strcpy(org.organisation_name, "GeeksforGeeks");
strcpy(org.org_number, "GFG123768");
printf("Organisation Name : %s\n",
org.organisation_name);
printf("Organisation Number : %s\n",
org.org_number);
printf("Employee id : %d\n",
org.emp.employee_id);
printf("Employee name : %s\n",
org.emp.name);
printf("Employee Salary : %d\n",
org.emp.salary);
}
• Note:
• Whenever an embedded nested structure is
created, the variable declaration is
compulsory at the end of the inner structure,
which acts as a member of the outer
structure. It is compulsory that the structure
variable is created at the end of the inner
structure.
struct Student {
int roll_no;
char name[30];
char branch[40];
int batch;
};
// variable of structure with pointer defined
struct Student s, *ptr;
int main()
{
ptr = &s;
// Taking inputs
printf("Enter the Roll Number of Student\n");
scanf("%d", &ptr->roll_no);
printf("Enter Name of Student\n");
scanf("%s", &ptr->name);
printf("Enter Branch of Student\n");
scanf("%s", &ptr->branch);
printf("Enter batch of Student\n");
scanf("%d", &ptr->batch);
return 0;
}
How to Return Structure from a
#include<stdio.h>
Function?
struct wage{
char name[50];
int rs;
};
struct wage employee();
int main(){
struct wage e;
e = employee();
printf("\nWage details of the employee\n");
printf("Name : %s",e.name);
printf("\nWage : %d",e.rs);
return 0;
struct wage employee(){
struct wage e1;
return e1;
}
How to Pass Structure by Reference
#include<stdio.h>
struct car
{
char name[20];
int seat;
char fuel[10];
};
void print_struct(struct car *);
int main()
{
struct car tata;
printf("Enter the model name : ");
scanf("%s",tata.name);
printf("\nEnter the seating capacity : ");
scanf("%d",&tata.seat);
printf("\nEnter the fuel type : ");
scanf("%s",tata.fuel);
print_struct(&tata);
void print_struct(struct car *ptr)
{
printf("\n---Details---\n");
printf("Name: %s\n", ptr->name);
printf("Seat: %d\n", ptr->seat);
printf("Fuel type: %s\n", ptr->fuel);
printf("\n");
}
An Array of Structures as Function Arguments
#include<stdio.h>
struct details {
char name[20];
char sec[20];
float per;
};
void print_struct(struct details str_arr[]);
int main()
{
struct details student[3] = {
{
"Aisiri","A",89.6
},
{
"Gourav","B",60.4
},
{
"Samuel","C",98.4
},
};
print_struct(student);
return 0;
void print_struct(struct details str_arr[]) {
int i;