is actual argument an array or singular pointer?

Quiz: pretend to be a typical c/c++ function at run time. If one of the arguments to the function is declared an int* pointer, how do you know if real thing is an array or a single pointer?

A: if this is the only argument, then you can’t tell. There has to be another argument like “int size”
A: however, if the argument is char*, then there may not be a size argument. Assume C-string please.

As a function parameter, a simple pointer is indistinguishable from an array.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s