help in C++

Status
Not open for further replies.

handshakeit

Beta member
Messages
5
Hi All,

When we define the constant size of string, then it should take input of that particlur size but

it does not do so.
For example:-

char str[5];

The above string should take input of maximum size 5, but it can take input of any size greater

that 5.
Why it is so....???

Thanx:
Devs
 
Don't forget that when the size of a char string is declared, one of the spaces in memory is used for the null terminator (/0) at the end of the string. So, in you example, str would hold 4 characters.
 
handshakeit said:

The above string should take input of maximum size 5, but it can take input of any size greater

it will compile and maybe sometime work but it a very bad idear. when you declear char a[5] you are reserving space for 5 chars in memory. when you go over that space you are over riding memory space not reserve for it. this can have extremly un expected results.
 
Status
Not open for further replies.
Back
Top Bottom