Thread: can't display values of the array

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is still wrong:
    Code:
    int lab1_array[9]
    It should be:
    Code:
    int lab1_array[10]
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Feb 2014
    Posts
    27
    Quote Originally Posted by laserlight View Post
    This is still wrong:
    Code:
    int lab1_array[9]
    It should be:
    Code:
    int lab1_array[10]
    I love you so much ...It WORKED lol
    but seriously thanks .. so you were saying that if I have a number of variables I want to store in an array .. the size of the array have to be bigger than the total number of variables by +1 ... is that it or im wrong ?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by hummingdev
    I love you so much ...It WORKED lol
    but seriously thanks ..
    You're welcome.

    Quote Originally Posted by hummingdev
    so you were saying that if I have a number of variables I want to store in an array .. the size of the array have to be bigger than the total number of elements by +1 ... is that it or im wrong ?
    No, the size of the array is 10 (as in you want an array of 10 elements), hence you should declare it as:
    Code:
    int lab1_array[10]
    However, as was pointed out to you in post #4, the valid indices of this array would be the integers from 0 to 9, inclusive.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Feb 2014
    Posts
    27
    Quote Originally Posted by laserlight View Post

    No, the size of the array is 10 (as in you want an array of 10 elements), hence you should declare it as:
    Code:
    int lab1_array[10]
    However, as was pointed out to you in post #4, the valid indices of this array would be the integers from 0 to 9, inclusive.
    I see , I'll keep that in mind

    again thank you very much for your help and patience ..(I'm kinda slow ..sorry about that )
    now I have a better understanding of how arrays work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display average pixel values
    By defunktlemon in forum C# Programming
    Replies: 2
    Last Post: 02-04-2013, 09:48 PM
  2. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 01:32 PM
  3. How to display the values of a struct
    By m88g88 in forum C Programming
    Replies: 4
    Last Post: 02-15-2010, 06:07 PM
  4. Array won't display new values?
    By Kespoosh in forum C++ Programming
    Replies: 9
    Last Post: 03-17-2003, 09:22 PM
  5. Need help with display of array
    By BalanusBob in forum C# Programming
    Replies: 1
    Last Post: 04-19-2002, 11:19 PM