Showing posts with label Pointers. Show all posts
Showing posts with label Pointers. Show all posts

Monday, September 12, 2011

Addition and subtraction using pointer

addition & subtraction of a number from a pointer

#include<stdio.h>
#include<conio.h>
main()
{
    int a[]={10,20,30,40,50};
    int *j,*k;
    clrscr();
    j=a;   // or j=&a[0];
    k=a+4;  // or k=&a[4];
    printf("\n %d %d",*j,*k);
    j=j+2;
    k=k-1;
    printf("\n %d %d",*j,*k);
    getch();
    }

subtraction of using pointer

//subtraction of one pointer from another

#include<stdio.h>
#include<conio.h>
main()
{
    int a[]={10,20,30,45,67,56,74};
    int *i,*j;
    clrscr();
    i=&a[1];
    j=&a[5];
    printf("\n %d %d",j-i,*j-*i);
    getch();
    }

Popular 5 Posts Last 7 days