C Program to print nos. using pointer to them and refernces.

Posted: January 19, 2012 in Lab 2

Problem Statement- Create four integers, four pointers to these integers and four references to them. Store these pointers and references in two arrays and print out the values of four integers using these arrays.

#include<stdio.h>
int main()
{
	int n[4],*arr[4],*ref[4];
	int i;
	printf("Enter any 4 nos\n");
	for(i=0;i<4;i++)
		scanf("%d",&n[i]);
	for(i=0;i<4;i++)
		arr[i]=&n[i];
	for(i=0;i<4;i++)
		ref[i]=&*arr[i];
	for(i=0;i<4;i++)
		printf("%d ",*ref[i]);
	return 0;
}


	
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s