Type casting of pointer in C++ Programming Language

Type casting of pointer in C++ Programming Language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

Type casting of pointer in C++ Programming Language. The following code shows how to cast type of pointer in C plus plus Programming Language.

 

Code:

#include<iostream>
using namespace std;

int main()
{
    int a = 1025;
    int *p = &a;
    // Print Pointer Location and Value
    cout << "Location of pointer p is: " << p <<endl;
    cout << "Value of pointer p is: " << *p <<endl;


    char *c = (char*)&a;
    // Print Pointer Location and Value
    cout << "Location of pointer c is: " << c <<endl;
    cout << "Value of pointer c is: " << *c <<endl;


    return 0;
}

 

Output:

Location of pointer p is: 0x7ffee2d92a68
Value of pointer p is: 1025
Location of pointer c is: 
Value of pointer c is: 

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram