Lesson 2 of 23

Variables और Format Specifiers

9 min 20 XP

C में पहले variable का type declare करते हैं: int (पूर्ण संख्या), float/double (दशमलव), char (एक अक्षर)। Values print करने के लिए printf format specifiers का उपयोग करता है: int के लिए %d, double के लिए %f, char के लिए %c।

Example: edit me and press Run

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

%.2f दो दशमलव स्थानों तक print करता है। sizeof() बताता है कि कोई type कितने bytes लेता है। const variable बदला नहीं जा सकता।

Example: edit me and press Run

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

गलत specifier (जैसे int के लिए %f) लगाने पर कचरा print होता है। Interviewers format specifiers के बारे में सच में पूछते हैं!

Challenge

+20 XP

int variable marks में 87 और double variable percent में 87.5 रखें, फिर print करें: Marks: 87 Percent: 87.50

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