Saturday, March 25, 2017

sample program with struct in C(like classes in java)

#include stdio.h
#include string.h
struct Employee{

char name[500];
int age;
char sex[1];
};
int main(){
struct Employee emp,emp1;
strcpy(emp.name,"sudharsan");
emp.age =36;
strcpy(emp.sex,"M");

strcpy(emp1.name,"venkateshwar vipin ragavan");
emp1.age=72;
strcpy(emp1.sex,"M");


printf("name:  %s\n",emp.name);
printf("age:   %d\n",emp.age);
    printf("sex:   %s\n",emp.sex);


printf("name:  %s\n",emp1.name);
    printf("age:   %d\n",emp1.age);
    printf("sex:   %s\n",emp1.sex);
return 0;
}

No comments:

Post a Comment