Demonstrates the use of pointer declarations and operators. - C++ Data Type

C++ examples for Data Type:Pointer

Description

Demonstrates the use of pointer declarations and operators.

Demo Code

#include <iostream>
using namespace std;
void main()/*from   w  w  w  .j  av a 2  s .  co  m*/
{
   int num=123;           // A regular integer variable.
   int *p_num;            // Declares an integer pointer.
   cout << "num is " << num << "\n";  // Prints value of num.
   cout << "The address of num is " << &num << "\n";// Prints num's location.
   p_num = &num;          // Puts address of num in p_num, in effect making p_num pointto num. No * in front of p_num.
   cout << "*p_num is " << *p_num << "\n"; // Prints value of num.
   cout << "p_num is " << p_num << "\n";   // Prints location of num.
   return;
}

Result


Related Tutorials