references

This is a discussion on references within the C++ Programming forums, part of the General Programming Boards category; hey i was wondering exactly what a reference was in C++ and how to use so if u could help ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    references

    hey i was wondering exactly what a reference was in C++ and how to use so if u could help me id appreiciate it thanks
    hooch

  2. #2
    Unregistered
    Guest
    A reference is an alias for a variable. Look at the following code.

    int number=7;
    int &number2=number;
    cout<<"Number is: "<<number<<endl;
    cout<<"Number2 is: "<<numbers<<endl;
    number2=number2+2;
    cout<<"Number is: "<<number<<endl;
    cout<<"Number2 is: "<<number2<<endl;

    if this were compiled in a formal program, the output would be the following:

    Number is 7
    Number2 is 7
    Number is 9
    Number2 is 9

    Basically, the reference is another name for the variable and anything done to either is done to both. Good luck and keep working!!

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    so basically its the same as assigning a varaible to another variable accept with a & sign in front it?
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VC++ 2005 Express: missing references page
    By psychopath in forum Tech Board
    Replies: 1
    Last Post: 08-21-2006, 04:55 PM
  2. Arrays of references
    By Welshy in forum C++ Programming
    Replies: 16
    Last Post: 07-04-2005, 11:28 PM
  3. Vector of references
    By roktsyntst in forum C++ Programming
    Replies: 5
    Last Post: 04-15-2003, 06:40 PM
  4. declare references to references works!
    By ManuelH in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 07:14 AM
  5. Pointers and references...
    By SushiFugu in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 03:21 PM

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