Pointers in C

You,C Programming

Addresses and pointers in C

Let us declare a single variable and array, and see how they are placed in memory

/* Online C Compiler and Editor */
#include <stdio.h>

int main()
{
    printf("Declaring an integer and an integer array\n");
    int num=7853;
    int d[3] = {1,2,7};
    printf("num= %d\n",num);
    for(int i =0;i<3;i++)
        printf("Integer array element d[%d] = %d\n",i,d[i]);
    
    int  * pd = d;
    printf("addresss of d = %ld\n",pd);
    
    int  * pd0 = &(d[0]);
    printf("addresss of d[0] = %ld\n",pd0);

    int  * pe = d+1;
    printf("addresss of e = %ld\n",pe);
    
    int  * pd1 = &(d[1]);
    printf("addresss of d[1] = %ld\n",pd1);
        
    return 0;
}

Output:

Declaring an integer and an integer array
num= 7853
Integer array element d[0] = 1
Integer array element d[1] = 2
Integer array element d[2] = 7
addresss of d = 140727830638268
addresss of d[0] = 140727830638268
addresss of e = 140727830638272
addresss of d[1] = 140727830638272

Notes: