>
void abc( int arg[] ){}
> Passed a pointer pointing to first element for the array.
Passed a pointer to int. Period. It may be a pointer to any int anywhere, or it may be a nullptr.
1 2 3 4 5 6 7 8
|
[code]void abc( int arg[] ){}
// ...
int i = 89 ;
int a[] = { 1, 2, 3 } ;
abc( &i ) ; // pointer to int 'i'
abc( a ) ; // pointer to first element of 'a'
abc( nullptr ) ; // does not point to any object
|
> Allowed to move to any elements.
Yes. Provided the pointer actually points to an element in an array.
>
void bcd( int& arg ){}
> Passed a pointer pointing to the address of the arg.
Passed an alias for an integer. Do not - repeat DO NOT, repeat
DO NOT - think of a reference as 'a pointer that is automagically dereferenced'.
> Anything else we can do with this?
It is an alias for an int. You can do anything with it that you can do with the int it refers to; whatever you do with it would be done on the int that it is an alias for. You could assign a value to the int, you could take the adress of that int, you could compare that int with another int, and so on.
>
void efg( int (*arg)[132] ){}
Passed a pointer pointing to the whole array?
Yes.
> Can we use the function
int xyz[] = arg;
to store the array given into a xyz variable?
No.
arg
is a pointer to an array; it is not an array; and it is not a pointer to the first element of the array. You can store its value in another pointer to an array.
1 2 3 4
|
void efg( int (*arg)[132] )
{
int(*xyz)[132] = arg ;
}
|
>
void cde( int (&arg)[15] ){}
and
void def( int (&arg)[132] ){}
> Passed the address of the whole array or the block of memory being used for the array?
No. NO.
NO. Passed an alias for an array.
You could do anything using the alias that could be done on the array for which it is an alias.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int a = 89 ;
int* p = &a ; // p is a 'pointer to int'; it holds an adress
int& r = a ; // r is a 'reference to int'; it is an alias for i (another name by which i can be refereed to)
// the value of 'p' is an address; the address of 'p' &p is the address of the pointer -
// a 'pointer to a pointer to an int'.
// 'r' does not have either an address or a value of its own
// address of 'r' &r would yield the address of 'i' &i. it is a 'pointer to int - 'r' is an alias for 'i'
// the value of 'r' would yield the value of 'i'; 'r' is an alias for 'i'
int j = r ; // equivalent to int j = i ;
r = 4567 ; // equivalent to i = 4567 ;
// conceptually, whenever and where ever you use 'r' after its initialization,
// the implementation would substitute 'i' in the place of 'r'
|