& - What does it ...

This is a discussion on & - What does it ... within the C++ Programming forums, part of the General Programming Boards category; I am starting C++ and I have seen "&" this wery often. What does it do?...

  1. #1
    Unregistered
    Guest

    Unhappy & - What does it ...

    I am starting C++ and I have seen "&" this wery often. What does it do?

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Depends on the context it's used in. Here's some examples:
    Code:
    int i;
    &i  //in this case it's accessing the pointer to your int i
    
    if(1&0) //in this case it's a bitwise AND
    
    if((1==1)&&(2==2)) //in this case it's a logical AND

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    16
    You can use & to make a reference to variable too:

    int i = 3; // an int variable i
    int& ref = i; // a reference to i
    ref = 4; //now i has a value of 4

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21