Lesson 22 of 23

Structures (struct)Structures (struct)

11 min 35 XP

struct பல வகை fields-ஐ ஒரு புதிய type-ஆக இணைக்கும், உதாரணமாக ஒரு மாணவரின் பெயர், roll no, மதிப்பெண். typedef மூலம் சுருக்கமான பெயர் வைக்கலாம். Pointer மூலம் field-ஐ அணுக -> பயன்படுத்துங்கள்.

A struct groups fields of different types into a new type, like a student's name, roll number and marks. typedef gives it a short name, and -> accesses a field through a pointer.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

struct vs union: union-ல் எல்லா fields-ம் ஒரே memory-ஐப் பகிரும். இந்த வேறுபாடு C interview-களில் கேட்கப்படும்.

struct vs union: in a union all fields share the same memory. Expect this question in C interviews.

Challenge

+35 XP

n, பிறகு n மாணவர்களின் பெயர் மற்றும் மதிப்பெண் (int) படியுங்கள். struct array-ல் சேமித்து, அதிக மதிப்பெண் பெற்றவரின் பெயர் மற்றும் மதிப்பெண்ணையும் வகுப்புச் சராசரியையும் print செய்யுங்கள். Input: 3 Arun 78 Bala 95 Charu 88 Output: Topper: Bala 95 Average: 87.00

Read n, then n students' names and marks (int). Store them in an array of structs and print the topper and the class average. Input: 3 Arun 78 Bala 95 Charu 88 Output: Topper: Bala 95 Average: 87.00

Output Loading C (first time takes a few seconds)
Press Run to see the result here.