C++ Pointer declarations and operators

Description

C++ Pointer declarations and operators

#include <iostream>
using namespace std;
void main()/* w ww  . java 2  s  . c o  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;
}



PreviousNext

Related