Table of Contents
show
Displaying Person information using Pointers and structures
#include <stdio.h>
struct person
{
int age;
float weight;
};
int main()
{
struct person *personPtr, person1;
personPtr = &person1;
printf("Enter age: ");
scanf("%d", &personPtr->age);
printf("Enter weight: ");
scanf("%f", &personPtr->weight);
printf("Displaying:\n");
printf("Age: %d\n", personPtr->age);
printf("weight: %f", personPtr->weight);
return 0;
}
Output
C:\TDM-GCC-64>gcc 4_pointer_Structure_3.c
C:\TDM-GCC-64>a
Enter age: 3
Enter weight: 10
Displaying:
Age: 3
weight: 10.000000
Displaying student information using pointers and structures
#include<stdio.h>
struct student{
int sno;
char sname[30];
float marks;
};
int main ( )
{
struct student s;
struct student *st;
printf("enter sno, sname, marks:");
scanf ("%d%s%f", & s.sno, s.sname, &s. marks);
st = &s;
printf ("details of the student are");
printf ("Number = %d\n", st ->sno);
printf ("name = %s\n", st->sname);
printf ("marks =%f\n", st ->marks);
return 0;
}
Output
C:\TDM-GCC-64>gcc 4_pointer_Structure_4.c
C:\TDM-GCC-64>a
enter sno, sname, marks:101
abc
90
details of the student areNumber = 101
name = abc
marks =90.000000
Views: 0