My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.
Showing posts with label Implement Structure with pointers. Show all posts
Showing posts with label Implement Structure with pointers. Show all posts

Monday, 15 August 2011

Implement Structure with pointers

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();
}

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls