Get variable address with the address-of operator &, - C++ Operator

C++ examples for Operator:Address Operator

Description

Get variable address with the address-of operator &,

Demo Code

#include <iostream> 
 
int main() /*from   www . j av  a  2  s  .  c  o m*/
{ 
    unsigned short shortVar = 5; 
    unsigned 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


Related Tutorials