Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Using Structures (struct)

C Language Examples - Using Structures (struct)

C Language Examples C Language Examples

Use a structure (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

(

"

ID:

"

)

;

scanf

(

"

%d

"

, &

s

.

roll

)

;

printf

(

"

Score:

"

)

;

scanf

(

"

%f

"

, &

s

.

marks

)

;

printf

(

"

Display information:

\

n

"

)

;

printf

(

"

Name:

"

)

;

puts

(

s

.

name

)

;

printf

(

"

ID: %d

\

n

"

,

s

.

roll

)

;

printf

(

"

Score: %.1f

\

n

"

,

s

.

marks

)

;

return

0

;

}

The output is:



Input information:

名字: runoob

编号: 123

成绩: 89

Display information:

名字: runoob

编号: 123

成绩: 89.0

C Language Examples C Language Examples