can string in c occupy more characters than the size of it???

luvyogi's Avatar, Join Date: Apr 2007
Newbie Member
Hi All,
I am new to this forum..
I compiled a small program in c...
I just declared a string of size 5 and gave 8 characters but it accepts those 8 characters.It is not supposed to accepts that 8 characters know???
how it is possibel?
Can anybody tell me the reason?
why it happens?
please help me...

coderzone's Avatar, Join Date: Jul 2004
Team Leader
It will take but if you have some other variable space the other extra characters will go into the memory location of the other variables.
listendinesh's Avatar, Join Date: Aug 2007
Go4Expert Member
This is out of bound access to an array.this should lead a crash in WIN & UNIX progarmming env but in case of DOS it can run fine.Either way it is a logical problem it should not be done.
When we define a array , we get memory from Operating system. In this case you are using more memory than op sys given to you that extra memory may belong to some other variable or array etc......