Question

What does char a[' '] actually mean? I didn't find it in web. I tried it by my self and it takes dynamic array of char. What is the purpose and use of [' '] in programming?

Was it helpful?

Solution 3

In this definition

char a[' '];

character literal ' ' is promoted to int and its value is used as the size of the array. For example in ASCII the value of ' ' is equal to 32. So this is equivalent to

char a[32];

Take into account that in EBCDIC the value of character literal ' ' is not equal to 32 and if I am not mistaken it is equal to 64.

So depending on selected coding the size of the array will be different.

For ASCII

char a[32];

For EBCDIC

char a[64];

OTHER TIPS

' ' is a character literal, it has the type char - so this is really just a number.

You system is probably using ascii, in which case the ascii value of a space is 32, so this would be the same as

char a[32];

' ' is a char literal with value 32 (ASCII code of whitespace). So char a[' '] is just char a[32].

char a[' '] which has the character constant ' ' character. The integer equivalent of which is 32, the array will be declared of size 32. char a[32]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top