Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   can string in c occupy more characters than the size of it??? (http://www.go4expert.com/forums/string-c-occupy-characters-size-t5928/)

luvyogi 19Aug2007 12:12

can string in c occupy more characters than the size of it???
 
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...

regards,
yoga

coderzone 19Aug2007 12:47

Re: can string in c occupy more characters than the size of it???
 
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 20Aug2007 13:14

Re: can string in c occupy more characters than the size of it???
 
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......


All times are GMT +5.5. The time now is 23:02.