-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-struct_ptr_basics.c
37 lines (29 loc) · 980 Bytes
/
01-struct_ptr_basics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<stdio.h>
struct Student {
char name[30];
int age;
int roll_number;
};
int main() {
struct Student student_1;
// Structure pointer
struct Student *sp = &student_1;
printf ("Enter the details of the Student (student_1)\n");
printf ("\tName: ");
scanf ("%s", sp->name);
printf ("\tAge: ");
scanf ("%d", &sp->age);
printf ("\tRoll Number: ");
scanf ("%d", &sp->roll_number);
// Access through -> operator
printf ("\n Display the details of the student_1 using Structure Pointer\n");
printf ("\tName: %s\n", sp->name);
printf ("\tAge: %d\n", sp->age);
printf ("\tRoll Number: %d\n", sp->roll_number);
// Display using * and . operators
printf ("\n Display the details of the student_1 using Structure Pointer\n");
printf ("\tName: %s\n", (*sp).name);
printf ("\tAge: %d\n", (*sp).age);
printf ("\tRoll Number: %d\n", (*sp).roll_number);
return 0;
}