Array pointer and Array are the same?

  • Thread starter Thread starter Kenny
  • Start date Start date
K

Kenny

Will is affect the result if I pass Array Pointer as a parameter to a
function compare to Array as a parameter?
For example,
BYTE buffer[1024]
a.) function(&buffer)
b.) function(buffer)
Is it any differences between (a) and (b)?
Thanks in advance.

Kenny
 
Hello Kenny,
Will is affect the result if I pass Array Pointer as a parameter to a
function compare to Array as a parameter?
For example,
BYTE buffer[1024]
a.) function(&buffer)
b.) function(buffer)
Is it any differences between (a) and (b)?

buffer == &buffer == &buffer[0]
 
a. function prototype (it seems) does not allow. &buffer is
BYTE(*)[1024].
This means, pointer to a BYTE array with size of 1024 elements. But
function, as far as I can understand, expects either BYTE[], or a
BYTE*.

the function prototype that would accept your example should be

int f(BYTE (*pArr)[1024[);


b. function prototype is either BYTE[] or BYTE* (I guess, may be a void
pointer, or something else that accepts any of BYTE[] or BYTE*). In
that case, "b" should compile, but "a" should give an error.

if your intent is to write something that can accept both arrays and
arrays of arrays, try to use templates.

Ismail Pazarbasi
 
Back
Top