c - Apostrophe in char data type -



c - Apostrophe in char data type -

char c; c = '2'; printf("%d\n",c);

so question quiz, asking display. reply 50, tried using program, why 50? not 2 or anything?

the apostrophes mean "character literal", i.e. '2' not integer 2, instead character 2, i.e. glyph used represent single digit 2.

you print value using %d in printf(), means "signed integer", integer value of character, called "code point" (or, classically, it's "ascii value").

i think code not 100% clean, since char might unsigned, should cast (int) in phone call clear, since int %d expects.

c arrays char structure apostrophe

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -