Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Question on arrays way number works

This topic is 5505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say with: int numbers[10]; i would be able to enter 10 numbers from 0 to 9 but with: char text[5]="here"; it will only accept the four letters not five. but with: char text2[5]; i can do text2[0]=''a'' ..etc ..etc ..etc text2[4]=''e'' why is this?

Share this post

Link to post
Share on other sites
You can certainly put five *letters* in the text array, but then it won''t be a valid C string (for use with strcpy, strstr, strlen, etc.), because it''s not null-terminated. By the way, in your example, text is holding five *characters*: ''h'', ''e'', ''r'', ''e'', and ''\0''.

Dave Mikesell Software & Consulting

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!