Home >Backend Development >C++ >Comparison of pointers and arrays in C language

Comparison of pointers and arrays in C language

PHPz
PHPzforward
2023-08-26 21:53:09973browse

Comparison of pointers and arrays in C language

Most of the time in c pointers and arrays are considered the same. Some differences are:

&operator:

  • &pointer = Returns the address of the pointer.

  • &array = Returns the address of the first element.

sizeof operator:

  • sizeof( array) = Returns the total memory consumed by all elements of the array.

  • sizeof(pointer) = Returns the only memory consumed by the pointer variable itself.

Array variables cannot be reassigned, but pointer variables can.

Statement:

int a[]; //array
Int *p; //pointer

Let us consider that there is an integer pointer variable

int *i;

Now let us consider the result of the following job -

a = &i; //illegal assignment. a variable can not be updated or modified.
p = &i; //legal assignment.

The above is the detailed content of Comparison of pointers and arrays in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete