Arrays and loops

This is a discussion on Arrays and loops within the C++ Programming forums, part of the General Programming Boards category; Will this code create an array like this: 1,2,3,4,5,6,7,8,9,10? int i_array[10]; for(int i=0; i<=10; i++) { i_array[i] = i; } ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    367

    Arrays and loops

    Will this code create an array like this: 1,2,3,4,5,6,7,8,9,10?

    int i_array[10];

    for(int i=0; i<=10; i++)
    {
    i_array[i] = i;
    }
    I couldn't be bothered to search for something similar or to read the FAQ.
    Last edited by Zewu; 05-25-2002 at 09:51 AM.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Are you a troll?

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    for(int i=0; i<=10; i++)
    Don't do that. You declare 10 cells but loop thu 11!

    Try this:

    for(int i=0; i < 10; i++)
    i_array[i] = i+1;


    ...but yeah, you were close...
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  4. #4
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    The good thing about questions is that they are never stupid. It's people that...
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using arrays and loops for math
    By LLINE in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2008, 04:09 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. while loops with arrays
    By volk in forum C Programming
    Replies: 2
    Last Post: 02-04-2003, 06:22 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. loops and arrays
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-03-2001, 03:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21