How much memory is reserved when i declare a string?

Posted by Bhagya on Stack Overflow See other posts from Stack Overflow or by Bhagya
Published on 2010-04-07T04:43:01Z Indexed on 2010/04/07 4:53 UTC
Read the original article Hit count: 192

Filed under:
|

What exactly happens, in terms of memory, when i declare something like: char arr[4];

How many bytes are reserved for arr?

How is null string accommodated when I 'strcpy' a string of length 4 in arr?

I was writing a socket program, and when I tried to suffix NULL at arr[4] (i.e. the 5th memory location), I ended up replacing the values of some other variables of the program (overflow) and got into a big time mess.

Any descriptions of how compilers (gcc is what I used) manage memory?

© Stack Overflow or respective owner

Related posts about c

    Related posts about memory-allocation