#String literals & character arrays

19 messages · Page 1 of 1 (latest)

wintry rain
#

Why does this work int buffer[] = {'a', 'v', 'q'} but this won't int buffer[] = "hello", even tho string literal is literally a null terminated char array?

swift egretBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wintry rain
#

I think it's the extra conversion step that C won't do to convert string literals to char arrays, and then characters to ASCII equivalents when assigning to an integer array.

robust umbra
#

Char literals are actually ints

#

But it's not that relevant

dreamy smelt
wintry rain
dreamy smelt
#

because that's an initializer for an int array

#

those character literals have type int

wintry rain
#

oh

#

that makes sense

#

so this won't work right?

#
char buffer[] = {'a', 'b'};
int bugger[] = buffer;
#

I mean this is what I'm essentially trying to do with the string literal except it has a null character at the end

dreamy smelt
#

no, you can't assign into an array like that

#

buffer isn't a valid initializer

dreamy smelt
wintry rain
#

!solved