0

what is char text[20];? and why index 20 is taken in the array

15th Oct 2020, 4:58 AM
SURYA TEJ PATTEM
SURYA TEJ PATTEM - avatar
5 Respuestas
+ 6
Here you defined char array text which type is character type . And you mentioned array size 20 it means your array can store 20 characters. For example char text[5]= "Helloworld"; Here i gave array size 5 and my total chars are 10 so it will give you errors so it represent your size . If u dont want to mention size the u can write like this char text[ ]= "Helloworld"; Here in bracket don't mention size your array will take size automatically and it will run without error.
15th Oct 2020, 5:12 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
LastSecond959 yes you saying right if you have doubts you can print length your doubt will be clear
17th Oct 2020, 2:59 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
when defining that variable, you have to specify size of character array. In your case it is 20.
15th Oct 2020, 5:02 AM
Raj Chhatrala
Raj Chhatrala - avatar
0
how 20 can you explain to me, please
15th Oct 2020, 5:03 AM
SURYA TEJ PATTEM
SURYA TEJ PATTEM - avatar
0
Supporting ♨️TEJAS MK-82♨️ 's answer, Technically yes, you declared an array of chars of size 20, it has the index of [0] to [19] but I suggest you assign a value to it for maximum of 19 characters (until index [18], because index [19] will be used as a string terminator, the '\0' character). The point is, it is correct to say it CAN store 20 characters, but you SHOULD store 19.
17th Oct 2020, 2:55 AM
LastSecond959
LastSecond959 - avatar