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.