size of integer arrays

This is a discussion on size of integer arrays within the C++ Programming forums, part of the General Programming Boards category; How do I in C++ find the size of an integer array? For example, if int a[] = {1,2,3,4,5}; How ...

  1. #1
    steve8820
    Guest

    Question size of integer arrays

    How do I in C++ find the size of an integer array? For example, if
    int a[] = {1,2,3,4,5};

    How would I find the length of that array? Is there anything in C++ that I could use on this array that behaves like strlen for strings? Thanks

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Code:
    #include <iostream>
    using std::cout;
    
    int main()
    {
    	int found=0;
                    int array[] = {'1', '2', '3', '4', '5'};
    
    	for(i=0;found==0;i++)
    	{
    		if(array[i]=='')
    		{
    			cout << "The array is " << i << " characters big";
    			found=1;
    		}
    		else
    		{
    			cout << "Still searching...\n";
    		}
    	}
    
    	return 0;
    }
    i donno if this works, but something like this
    Last edited by Okiesmokie; 03-06-2002 at 06:23 PM.

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    >How would I find the length of that array?

    you don't

    >Is there anything in C++ that I could use on this array that behaves like strlen for strings?

    no

    this is technically impossible since no value is reserved for the end of the array.

    define a value to size the array or keep track of it by some other means

    #define ARRAY_LENGTH 5

    and use ARRAY_LENGTH where ever you need the array size
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 07:45 PM
  2. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  3. Replies: 11
    Last Post: 03-25-2003, 04:13 PM
  4. Linked Lists Integer addition ? HELP Please??
    By green_eel in forum C Programming
    Replies: 3
    Last Post: 03-12-2003, 03:36 PM
  5. Arrays of user-defined size?
    By Captain_Penguin in forum C++ Programming
    Replies: 7
    Last Post: 09-12-2002, 04:07 PM

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