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

Discussion in 'C' started by luvyogi, Aug 19, 2007.

  1. luvyogi

    luvyogi New Member

    Joined:
    Apr 2, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    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.
     
  3. listendinesh

    listendinesh New Member

    Joined:
    Aug 3, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    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......
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice