Pointer Representation and Pointer Example Programs


Pointer Definition

Pointer is a programming language data type whose value refers directly to (or "points to") another 

value stored elsewhere in the computer memory using its address.

Accessing The Address:

& - Locate the Variable Address

&variable

ponter_variable = &variable;

Pointer Representation

// Example program for Pointer Representation 
#include<stdio.h>
#include<conio.h>
void main()
{
	int i=10;
	printf("\nValue Of i :%d",i);
	printf("\nAddress Of i :%d",&i);
}

Declaring Pointer Variables

  • * and varibale name 
  • pointer variable points to a variable of type data_type 

Syntax:

data_type *pt_name;

Example:

int *p;

float *x;

Initialization Of Pointer Variable:

pointer_vaibale = &variable;

Pointer Example program : 1

// Pointer Representation Example Program : 1
#include<stdio.h>
#include<conio.h>
void main()
{
	// Declaring Variables
	int i=10;
	int *Ptr;
	
	// Assigning Pointer
	Ptr=&i;

	/ Printing Values of Pointer
	printf("\nValue Of i :%d",i);
	printf("\nAddress Of i :%d",&i);
	printf("\nValue Of Ptr :%d",Ptr);
	printf("\nAddress Of Ptr :%d",&Ptr);
	printf("\nPtr's Pointer Value:%d",*Ptr);
	printf("\nPtr Equal to &i :%d",*(&i));
}

Pointer Example Program : 2

// Pointer Representation Example Program : 2
#include<stdio.h>
#include<conio.h>
void main()
{
	// Declaring Variables and Pointer
	int i=10;
	int *Ptr;
	Ptr=&i;

	// Printing Values of Pointer
	printf("\nValue Of i :%d",i);
	printf("\nAddress Of i :%d",&i);
	printf("\nValue Of Ptr :%d",Ptr);
	printf("\nAddress Of Ptr :%d",&Ptr);
	printf("\nPtr's Pointer Value:%d",*Ptr);
	printf("\nPtr Equal to &i :%d",*(&i));

	// Change Values of Using Pointer
	printf("\n\nWe Can Change Value Of i,Without Using i");
	*Ptr=100;
	printf("\nValue Of i :%d",i);
	printf("\nAddress Of i :%d",&i);
	printf("\nPtr's Pointer Value:%d",*Ptr);
	getch();
}