C-Pointers What is the output

FAQ-1

void main()
{
	int *p = 91; //compilation error
	printf("%d \n", *p);
	printf("%d \n", p);
}
OUTPUT:
Does not compile
error C2440: 'initializing' : cannot convert from 'int' to 'int *'

FAQ-2

void main()
{
	int i = 91;
	int *p = &i;

	printf("%d \n", *p);
	printf("%d \n", p);
}
OUTPUT:
91
1245024

FAQ-3

void main()
{
	int i = 91;
	int *p = &i;

	printf(" *p = %d \n", *p);
	printf("  p = %d \n", p);
	printf(" &p = %d \n", &p);
	printf(" *(&p) = %d \n", *(&p));
	printf(" *(*(&p)) = %d \n", *(*(&p)));
}

OUTPUT:
 i = 91
 &i = 1245024
 *p = 91
  p = 1245024
 &p = 1245012
 *(&p) = 1245024
 *(*(&p)) = 91

FAQ-4

void main()
{
  const int *p;
  int i;
  i = 10;
  p = &i;
  printf("p = %d, *p = %d, i = %d", p, *p, i);
}
OUTPUT
p = 1245012, *p = 10, i = 10
About these ads

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 )

Connecting to %s