Pointer vs Array (C Programming) | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Vishal Gulia.

Please Like, Comment and Share the Video among your friends.

Install our Android App:

If you wish, translate into local language and help us reach millions of other geeks:

Follow us on Facebook:

And Twitter:

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

Two things need to be said about this, &array does NOT point to the first element of the array, it points to the ENTIRE array, which just happens to be numerically the same with the address of the first element of the array (since any array starts from its first element). The difference is in pointer arithmetics, if arr is declared the following way:

int arr[5]= {1, 2, 3, 4, 5}
(arr+1) would be 1 integer size away from arr since arr points to the first integer of the array.
But (&arr+1) would be 5 integers size away from arr/&arr since &arr points to the entire array.

And char *arr= "xyz" initializes a string in the read-only part of the executable image memory (.rdata in Windows PE files, .rodata in Linux ELF), and assigns the starting address of the string to arr which in this case is a character pointer. This is possible only because C allows decaying string/array type to pointer, this does not mean though that (char *arr) and (char arr[]) are the same thing.

EvilSapphireR
Автор

&array is not an alias for &array[0]. If it were an alias for it, &array+1 would give the same output with &array[1]. &array just gives the whole array's adress. Not first element's adress of the array.

cgiscript
welcome to shbcf.ru