1. Structure exercise:
#include<stdio.h>
#include<string.h>
typedef struct _employee{
int id;
char name[40];
float salary;
} EMPLOYEE, *PEMPLOYEE;
int main(){
EMPLOYEE e1;
PEMPLOYEE p1 = &e1;
PEMPLOYEE *pp1 = &p1;
e1.id = 101;
strcpy(e1.name, "'Alice'");
e1.salary = 10000;
printf("The Id of employee %d, The name of employee %s, and salary %0.2f", e1.id, e1.name, e1.salary);
//Now with pointer update
p1->salary = 80000.75;
printf("The Id of employee %d, The name of employee %s, and salary %0.2f", p1->id, p1->name, p1->salary);
(*pp1)->salary = 150000;
printf("The Id of employee %d, The name of employee %s, and salary %0.2f", (*pp1)->id, (*pp1)->name, (*pp1)->salary);
return 0;
}
================================================================
Comments
Post a Comment