Computer Science, asked by gopaganipinky, 1 month ago

examine pointer to 1D array with a suitable example program​

Answers

Answered by chandraprakashkulora
2

Answer:

Last updated on July 27, 2020

In C, the elements of an array are stored in contiguous memory locations. For example: if we have the following array.

int my_arr[5] = {1, 2, 3, 4, 5};

Then, this is how elements are stored in the array.

Here the first element is at address 5000, since each integer takes 4 bytes the next element is at 5004 and so on.

In C, pointers and arrays are very closely related. We can access the elements of the array using a pointer. Behind the scenes compiler also access elements of the array using pointer notation rather than subscript notation because accessing elements using pointer is very efficient as compared to subscript notation. The most important thing to remember about the array is this:

The name of the array is a constant pointer that points to the address of the first element of the array or the base address of the array.

We can use subscript notation (i.e using square brackets) to find the address of the elements of the array. For example:

int my_arr[5] = {11, 22, 33, 44, 55};

here &my_arr[0] points to the address of the first element of the array. Since the name of the array is a constant pointer that points to the first element of the array, my_arr and &my_arr[0] represent the same address. &my_arr[1] points to the address of the second element. Similarly &my_arr[2] points to the address of the third element and so on.

Note: my_arr is of type (int *) or pointer to int.

Explanation:

please mark me as brainlist

Attachments:
Similar questions