c - Size of "const char " -
this question has answer here:
- size of character ('a') in c/c++ 3 answers
i understand "const" keyword makes variable assigned read variable , don't know reason why size of constant char 4 bytes (gnu c compiler ex.) making different size of "char" 1 byte .
as stated on cquestions blog first question 'a' const char
printf("%d",sizeof('a')); output: 4
'a' has type int not const char, character constants.
this extracted c11 draft
6.4.4.4 character constants
- an integer character constant sequence of 1 or more multibyte characters enclosed in single-quotes, in
'x'. wide character constant same, except prefixed letter l, u, or u. few exceptions detailed later, elements of sequence members of source character set; mapped in implementation-defined manner members of execution character set.
- an integer character constant has type int. value of integer character constant containing single character maps single-byte execution character numerical value of representation of mapped character interpreted integer. value of integer character constant containing more 1 character (e.g.,
'ab'), or containing character or escape sequence not map single-byte execution character, implementation-defined. if integer character constant contains single character or escape sequence, value 1 results when object typecharvalue of single character or escape sequence converted typeint.
i made bold important part it's visible.
Comments
Post a Comment