Array size in C as in Java?

This is a discussion on Array size in C as in Java? within the C Programming forums, part of the General Programming Boards category; In Java one can use foo.size or foo.size() if an ArrayList to determine the size of an array. Quite handy ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    178

    Array size in C as in Java?

    In Java one can use foo.size or foo.size() if an ArrayList to determine the size of an array. Quite handy for keeping "ArrayIndexOutOfBound" exceptions from being thrown but in C is there anything even remotely close to this?

    I would rather there be than to continuously write a function to determine the size of an array.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    There is not a similar function in C. Easiest way is to keep a second variable, an int, to track the size.

    However, C++ has equivalent methods.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    178
    Thanks Dino.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of array
    By goran00 in forum C Programming
    Replies: 38
    Last Post: 04-02-2008, 09:57 AM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 10:27 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Replies: 11
    Last Post: 03-25-2003, 04:13 PM

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