w3resource logo


C Programming Exercises

C Exercises: Show the basic declaration of pointer

Secondary Nav

C Pointer : Exercise-1 with Solution

Write a program in C to show the basic declaration of pointer.
Expected Output :

z stores the address of m  = 0x7ffe97a39854
 *z stores the value of m = 10
 &m is the address of m = 0x7ffe97a39854
 &n stores the address of n = 0x7ffe97a39858
 &o  stores the address of o = 0x7ffe97a3985c
 &z stores the address of z = 0x7ffe97a39860

C Code:

#include <stdio.h>
void main(void)
{
int m=10,n,o;
int *z=&m ;

	printf("\n\n Pointer : Show the basic declaration of pointer :\n");
	printf("-------------------------------------------------------\n"); 
	printf(" Here is m=10, n and o are two integer variable and *z is an integer");	
	printf("\n\n z stores the address of m  = %p\n",  z); // z is a pointer so %p would print the address
	printf("\n *z stores the value of m = %i\n",   *z); 
	printf("\n &m is the address of m = %p\n",   &m); // &m gives the address of the integer variable m 
                             // so %p is the specifier for that address
	printf("\n &n stores the address of n = %p\n",   &n);
	printf("\n &o  stores the address of o = %p\n",   &o);
	printf("\n &z stores the address of z = %p\n\n", &z); // &z gives the address, where the pointer z is 
                             // stored -> still an address -> %p is the right
                             // specifier        
}

Flowchart :

Flowchart: Show the basic declaration of pointer

C Practice online:


#include <stdio.h>
void main(void)
{
int m=10,n,o;
int *z=&m ;

	printf("\n\n Pointer : Show the basic declaration of pointer :\n");
	printf("-------------------------------------------------------\n"); 
	printf(" Here is m=10, n and o are two integer variable and *z is an integer");	
	printf("\n\n z stores the address of m  = %p\n",  z); // z is a pointer so %p would print the address
	printf("\n *z stores the value of m = %i\n",   *z); 
	printf("\n &m is the address of m = %p\n",   &m); // &m gives the address of the integer variable m 
                             // so %p is the specifier for that address
	printf("\n &n stores the address of n = %p\n",   &n);
	printf("\n &o  stores the address of o = %p\n",   &o);
	printf("\n &z stores the address of z = %p\n\n", &z); // &z gives the address, where the pointer z is 
                             // stored -> still an address -> %p is the right
                             // specifier        
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables