Pointers in C & C++

C pointers

In C++,Variable is stored in memory blocks.Each memory block has a unique address.So in order to call the value,we stimulate the address of the block.So that address is represented as pointers.

In simple terms,pointers are used to call addresses.
It is represented as * symbol.

Topic

  • Syntax of pointer in c++
  • Code to show the use of pointer

Syntax


Define a pointer.
Assign the address of the variable to the pointer.

int a=100;
int *ptr;
ptr=&a;

Solution


#include <iostream> 
using namespace std; 
int main()   //main function
{
int a=100;   //assign value to a variable
int *ptr;    //pointer declaration
ptr=&a;      //assign address to pointer
cout<<ptr<<endl;   //print address
cout<<*ptr;   //print value of address
return 0;
}

About the Author: Rishab Khuntia

Leave a Reply

Your email address will not be published. Required fields are marked *