Easy Tutorial
❮ C Exercise Example65 C Variable Arguments ❯

C Language Example - Using Structures (struct)

C Language Examples

Using structures (struct) to store student information.

Example

#include <stdio.h>
struct student
{
    char name[50];
    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("Display information:\n");

    printf("Name: ");
    puts(s.name);

    printf("Roll number: %d\n", s.roll);

    printf("Marks: %.1f\n", s.marks);

    return 0;
}

Output:

Enter information:
Name: tutorialpro
Roll number: 123
Marks: 89
Display information:
Name: tutorialpro
Roll number: 123
Marks: 89.0

C Language Examples

❮ C Exercise Example65 C Variable Arguments ❯