pointer arithmetics

// pointer arithmetic
// only these arithmetic operation we can do with pointers that is addition and subtraction
// 1. +
// 2. -
// 3. ++
// 4. --

#include <stdio.h>
int main()
{
    int a=1;
    int *ptr1=&a; //pointer
    printf("value of pointer points to a: %d\n",*ptr1);
    printf("address of pointer points to a: %d\n",ptr1);
    printf("addtion of pointer points to a: %d\n",ptr1+1); //this will add the address number by the int data type size(4byte)
    printf("subtraction of pointer points to a: %d\n\n",ptr1-1); //this will subtract the address number by the int data type size(4byte)
   
    printf("address of pointer points to a: %d\n",ptr1);
    ptr1++; // it means (ptr11=ptr1+1)
    printf("addition of pointer points to a: %d\n",ptr1);
    return 0;
}

Comments

Popular posts from this blog

Tokens in C

Steps taken by a compiler to execute a C program

Variables and Data Types in C