Lesson 22 of 23

Structures (struct)

11 min 35 XP

struct अलग-अलग types के fields को एक नए type में बाँधता है, जैसे छात्र का नाम, roll number और अंक। typedef उसे छोटा नाम देता है, और -> pointer के ज़रिए field तक पहुँचता है।

Example: edit me and press Run

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

struct बनाम union: union में सभी fields एक ही memory साझा करते हैं। C interviews में यह सवाल अपेक्षित है।

Challenge

+35 XP

n पढ़ें, फिर n छात्रों के नाम और अंक (int)। उन्हें structs के array में रखें और topper व class का औसत print करें। 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.