Array Pointer

The address of an array element can be expressed in two ways

  1. By writing the actual array element preceded by the ampersand (&) sign.
  2. By writing an expression in which the subscript is added to the array name.

Array Using Pointer

#include<stdio.h>
#include<conio.h>
int main(){
	int i;
    int a[5] = {1, 2, 3, 4, 5};
    int *p = a;     // same as int*p = &a[0]
    for (i = 0; i < 5; i++)
    {
        printf("\n%d", *p);
        p++;
    }
	return 0;
}

Output:

1
2
3
4
5

Replacing the printf("%d", *p); statement of above example, with below mentioned statements. Lets see what will be the result.

printf("%d", a[i]); இவாறு print செய்தால் incrementing index value print ஆகும்.

printf("%d", ¡[a] ); array-ன் elements print ஆகும்.

printf("%d", a+i); அனைத்து array elements-ன் address print ஆகும்.

printf("%d", t(a+i)); array element-ன் value print ஆகும்.

printf("%d", *a); a[0]-ன் value மட்டும் print ஆகும்.

a++; Compile time error, array-வின் base address-ஐ change பன்ன இயலாது.

Comments