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

Comparison of pointers and arrays in C language

PHPz
Release: 2023-08-26 21:53:09
forward
1010 people have browsed it

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
Copy after login

Let us consider that there is an integer pointer variable

int *i;
Copy after login

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.
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template