Copyright © Programs ++
Design by Dzignine
Thursday, 26 January 2012

Use of '&' operator in C++


// Program to demonstrate the use of &(ampersand) operator
#include <iostream>

int main()
{
    int x,y;
    std::cout<<" Enter the value of x : ";
    std::cin>>x;
    std::cout<<" The VALUE of x is : "<<x;
    std::cout<<" \n The ADDRESS of x is : "<<&x; // displays the address of x
    std::cin.get(); // displays the output
    return 0;
} // end of main










1 comments:

  1. Nice tut guy. But my question is that must we reference another variable when using pointers. For E.g;

    int me, you;
    int *theptr;
    theptr=me;
    theptr=you;
    theptr=&me;// Here is the base of my question.
    theptr=10;
    theptr=&you;
    theptr=20;// Anothe base for my question.
    ...And other codes.
    And again since we never initialize the value for the address, how is it used when writting real programs or how can we know the output of it. Do we do that for formalities or what?
    Please you can correct me if my question is not well framed. Thanks

    ReplyDelete

Comment Here....