Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualiMalc

Posted 21 July 2012 - 04:26 PM

Still just the size of a pointer there. Note that you got the [] in the wrong place though. In C++ it comes after the variable name.

The bit of knowledge that you are lacking which would enable you to work out why it is like this, and answer the question for yourself, is that sizeof gets replaced with a single number at compile time. That clearly demonstrates how neither checkSize function case could result in returning the size of the array whose pointer was passed in, because there is no way for this function to return anything but the same value every time.
Then if you think about how it is used in main (which incidentally must return int, not void) The array that you are using it on can only be of one size, so you get that array's size no problem.

#1iMalc

Posted 21 July 2012 - 04:25 PM

Still just the size of a pointer there. Note that you got the [] in the wrong place though. In C++ it comes after the variable name.

The bit of knowledge that you are lacking which would enable you to work out why it is like this, and answer the question for yourself, is that sizeof gets replaced with a single number at compile time.
That clearly demonstrates how neither case could result in returning the size of the array whose pointer was passed in, because there is no way for this function to return anything but the same value every time.
Then if you think about how it is used in main (which incidentally must return int, not void) The array that you are using it on can only be of one size, so you get that array's size no problem.

PARTNERS