Showing posts with label Pointer variables. Show all posts
Showing posts with label Pointer variables. Show all posts

Wednesday, April 8, 2015

Pointer variables

Algorithm
Step 1 : Initialize two integer variables x and y with some values.
Step 2 : Create a pointer iptr of integer type
Step 3 : Assign the address of x to iptr
Step 4 : Print the value and address stored in iptr
Step 5 : Assign the address of y to iptr
Step 6 : Print the value and address stored in iptr
Step 7 : Print the storage requirement of iptr, address of iptr and main function

Program (ptrvar.c)

/* Pointer variables */
# include<stdio.h>
main()
{
int x, y, *iptr;
x = 125;
iptr = &x ; /* iptr points to x */
y = 23;
float *fptr;
printf("X value is %d and stored at %u\n", x, &x);
printf("Y value is %d and stored at %u\n", y, &y);
printf("\nInt pointer holds the address %u\n", iptr);
printf("Aceesing value thru pointer : %d\n", *iptr);
iptr = &y; /* iptr points to y */