c - Size of "const char " -


this question has answer here:

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

  1. 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.

  1. 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 type char value of single character or escape sequence converted type int.

i made bold important part it's visible.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -