Cpp - Operator Address Operator

Introduction

You can use the address-of operator & to get variable memory address.

Demo

#include <iostream> 
 
int main() /* www  .  j av a2  s.  co m*/
{ 
    short shortVar = 5; 
    long  longVar = 65535; 
    long sVar = -65535; 
 
    std::cout << "shortVar:\t" << shortVar; 
    std::cout << "\tAddress of shortVar:\t" << &shortVar << "\n"; 
    std::cout << "longVar:\t"  << longVar; 
    std::cout << "\tAddress of longVar:\t"  << &longVar  << "\n"; 
    std::cout << "sVar:\t\t"   << sVar; 
    std::cout << "\tAddress of sVar:\t"     << &sVar     << "\n"; 
 
    return 0; 
}

Result