You are on page 1of 1

Example: A program to display the content and the address of a pointer variable using different types of incrementation. #include<iostream.

h> { int x,y; int *ptr1, *ptr2; x = 20; ptr1 = &x; cout<< Content of a pointer = *ptr1<<endl; *ptr1 = *ptr + 1; // (*ptr1++) Y = *ptr1; cout<< Value of Y =<<y<<\t; cout<< and pointer *ptr1 = *ptr + 1 =<<*ptr1<<endl; *ptr1 ++ = 1; // (*ptr1++) y = *ptr1; cout<< Value of Y =<<y<<\t; cout<< and pointer *ptr1 += 1 =<<*ptr1<<endl; (*ptr)++; y = *ptr1; cout<< Value of Y =<<y<<\t; cout<< and pointer (*ptr1)++ = <<*ptr1<<endl; ++ *ptr1; y = *ptr1; cout<< Value of Y =<<y<<\t; cout<< and pointer (++*ptr1) = <<*ptr1<<endl; ++ *ptr1; ptr2 = ptr1; cout<< Pointer 1 =<<*ptr1<<\t; cout<< And Pointer 2 =<<*ptr2<<endl; } Output: Content of a pointer = 20 Value of Y = 21 and pointer *ptr1 = *ptr + 1 = 21 Value of Y = 21 and pointer *ptr1 += 1 = 22 Value of Y = 21 and pointer (*ptr1)++ = 23 Value of Y = 21 and pointer (++*ptr1) = 24 Pointer 1 = 25 and Pointer 2 = 25

You might also like