0% found this document useful (0 votes)
6 views1 page

Student Structure and Data Input

This C program demonstrates the use of structures and pointers to structures by defining a 'student' structure that includes personal details and a date structure for the date of admission. It allows the user to input details for two students, storing the first in a stack-allocated structure and the second in a dynamically allocated structure. The program then prints the details of both students.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Student Structure and Data Input

This C program demonstrates the use of structures and pointers to structures by defining a 'student' structure that includes personal details and a date structure for the date of admission. It allows the user to input details for two students, storing the first in a stack-allocated structure and the second in a dynamically allocated structure. The program then prints the details of both students.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

// PRogram that demonstrate the structure and pointer to structure

#include<stdio.h>
#include<stdlib.h>

struct date
{ int dd;
int mm;
int yyyy;
};

struct student
{ int rollno;
char name[20];
struct date doa;
float cgpa;
struct student *l;
};

int main()
{
struct student s1;

printf("\nEnter S1 roll number : "); scanf("%d", &[Link]);


printf("\nEnter S1 name : "); scanf("%s", &[Link]);
printf("\nEnter S1 date of admin: "); scanf("%d/%d/%d", &[Link],
&[Link], &[Link]);
printf("\nEnter S1 cgpa : "); scanf("%f", &[Link]);s1.l=NULL;
printf("\nDetails of Student s1\n ");
printf("\nroll = %d",[Link]);
printf("\nname = %s", [Link]);
printf("\nDoA = %d/%d/%d", [Link], [Link], [Link]);
printf("\ncgpa = %4.2f", [Link]);

struct student *ptrs2;


printf("\n\n\n Enter Another Student Details ");
ptrs2= (struct student*)malloc(sizeof(struct student));
printf("\nEnter S2 roll number : "); scanf("%d", &ptrs2->rollno);
printf("\nEnter S2 name : "); scanf("%s", &ptrs2->name);
printf("\nEnter S2 date of admin: "); scanf("%d/%d/%d", &ptrs2-
>[Link], &ptrs2->[Link], &ptrs2->[Link]);
printf("\nEnter S2 1st year cgpa: "); scanf("%f", &ptrs2->cgpa); ptrs2-
>l=NULL;
printf("\nDetails of Student s2\n ");
printf("\nroll = %d",ptrs2->rollno);
printf("\nname = %s", ptrs2->name);
printf("\nDoA = %d/%d/%d", (ptrs2->doa).dd, (ptrs2->doa).mm, (ptrs2-
>doa).yyyy);
printf("\ncgpa = %4.2f", ptrs2->cgpa);

return 1;
}

You might also like