View Single Post
Old Sep 2nd, 2007, 5:29 PM   #1
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
Passing int arrays as arguments...

I have a function in which i need to pass as argument an integer array. But how can I know the size of the integer array once this is inside the function?

For example, the following code:

cpp Syntax (Toggle Plain Text)
  1. void foo(unsigned *p)
  2. {
  3. cout << sizeof(p)/4 << '\n';
  4. }
  5.  
  6. int main (int argc, const char * argv[]) {
  7. unsigned p[] = {1,2,3,4,5,6,7,8,9,0};
  8. foo(p);
  9. return 0;

Will have as a result the number 1. If I try to use the sizeof operator in the main(), it will have the expected results, however, once the pointer of the array is passed as an argument, it seems I cannot use the sizeof operator.

Any ideas?
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote