Write a Program in C to Implement Structure with pointers
#include<stdio.h>#include<conio.h>
struct student
{
int roll;
char name[50];
int age;
};
void main()
{
struct student s1,s2;
struct student *ps1,*ps2;
printf("Enter Roll Number\n");
scanf("%d",&s1.roll);
printf("\nEnter name\n");
scanf("%s",&s1.name);
printf("\nEnter age\n");
scanf("%d",&s1.age);
ps1=&s1; //ps1 will point to s1 of type structure "student"
printf("\n\nEnter Roll Number\n");
scanf("%d",&s2.roll);
printf("\nEnter name\n");
scanf("%s",&s2.name);
printf("\nEnter age\n");
scanf("%d",&s2.age);
ps2=&s2; //ps1 will point to s2 of type structure "student"
printf("\n\nRoll Number \t Name \t\t Age\n\n");
printf(" %d \t \t %s \t %d \n",ps1->roll,ps1->name,ps1->age);
printf(" %d \t \t %s \t %d \n",ps2->roll,ps2->name,ps2->age);
getch();
}
No comments:
Post a Comment