C Examples Structure Store Information
# C Example - Using Structs (struct)
[ C Examples](#)
Using structs (struct) to store student information.
## Example
```c
#include
struct student
{
char name;
int roll;
float marks;
} s;
int main()
{
printf("Enter information:n");
printf("Name: ");
scanf("%s", s.name);
printf("Roll number: ");
scanf("%d", &s.roll);
printf("Marks: ");
scanf("%f", &s.marks);
printf("Displaying Information:n");
printf("Name: ");
puts(s.name);
printf("Roll number: %dn", s.roll);
printf("Marks: %.1fn", s.marks);
return 0;
}
The output is:
Enter information:
Name: tutorial
Roll number: 123
Marks: 89
Displaying Information:
Name: tutorial
Roll number: 123
Marks: 89.0
[ C Examples](#)
[](#)(#)
(#)[](#)
[Volcengine Coding Plan supports Doubao, GLM, DeepSeek, Kimi, MiniMax and other mainstream large models, officially supplied, stable and reliable. Configuration Guide Β₯9.9/month Subscribe Now](https://maas.xfyun.cn/modelSquare?ch=maas_lm_l2E)
## 1 Note Write Note
1. #0 AsSaSsIn
943***763@qq.com [](#)26 Calculating sizeof(struct) under two different alignment methods.
```c
#include "stdio.h"
struct {
int i;
char j;
} s1;
#pragma pack(1)
struct {
int i;
char j;
} s2;
int main(void)
{
int size_s1;
int size_s2;
size_s1 = sizeof(s1);
size_s2 = sizeof(s2);
printf("size_s1 under default alignment = %dn", size_s1);
printf("size_s2 under byte alignment = %dn", size_s2);
}
The output is:
size_s1 under default alignment = 8
size_s2 under byte alignment = 5
(javascript:;)AsSaSsIn
943***763@qq.com 7 years ago (2019-03-09)
### Click to Share Note
YouTip