简体   繁体   中英

“initialization makes integer from pointer without a cast” waning in array initialization

I am now starting to learn C. I would like to know why I get the warning. I declared a bidimensional char array, but why the character "d" is not allowed?

char array[3][3] = {{1,"d",3},{3,2,1},{2,1,3}};

Replace "d" with 'd'

'd' is a character

"d" is a string

TL;DR -- "d" is not a character, it's a string . 'd' is a character.


To elaborate, we use single quotes '' to denote a char . It represents the value of that char . That value is int type.

OTOH, The double quotes " " are used to denote a string. It retruns the base address of the string . That is a pointer.

In your code, you have used "d" , which returns a pointer to a string literal , to initialize a char variable, which expects an value of type int . Hence the warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM