Pointer Program in Cpp 2022 - mymixindia.com

Pointer Program in Cpp 2022


The Pointers in CPP is used to locate the address of a variable and we can use this with other user-defined data types, functions also, the pointer are the special type of variable that store the address and can manipulate the value through the address access of a particular variable.

Pointer Program in Cpp 2022

//......Mymixindia.com......
//......Pointer Program in Cpp 2022.......
//........Pointer Program...........
#include<iostream>
using namespace std;

int main(){

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

cout<<"\n Welcome to the Pointer Program...\n";
cout<<"\n Pointer Program...\n";
cout<<"Value of a = "<<a<<endl;
cout<<"Address of a = "<<&a<<endl;
cout<<"Value of ptr = "<<ptr<<endl;
cout<<"Value of a by pointer = "<<*ptr<<endl;

    return 0;
}

The output of the Pointer Program

 Welcome to the Pointer Program...

 Pointer Program...
Value of a = 100
Address of a = 0x7bfe14
Value of ptr = 0x7bfe14
Value of a by pointer = 100  

 

 

Pointer with array Program 2022

//......Mymixindia.com......
//......Pointer Program in Cpp 2022.......
//........Pointers with Arrays...........
#include<iostream>
using namespace std;

int main(){

int a[4] = {23,45,56,24}; 
int *ptr;
ptr  = &a[0];

cout<<"\n Welcome to the Pointer Program...\n";
cout<<"\n Pointer with Array Program...\n";
cout<<"Value of a[0] = "<<a[0]<<endl;
cout<<"Value of a[1] = "<<a[1]<<endl;
cout<<"Value of ptr = "<<ptr<<endl;
cout<<"Value of a[1] by pointer = "<<*(ptr+3) + 1<<endl;

    return 0;
}

The output of the Pointer with array program

 Welcome to the Pointer Program...

 Pointer with Array Program...    
Value of a[0] = 23
Value of a[1] = 45
Value of ptr = 0x7bfe00
Value of a[1] by pointer = 25   

Related Posts:

Program to Print Prime Number in CPP 2020

5 Namespace Program in C++ 2022

Constructors Program in Java

Java Data Type Program

HTML Tutorials 

CSS tutorials