Results 1 to 2 of 2

Thread: Question about C++ references?

                  
   
  1. #1
    Junior Entrepreneur Array
    Join Date
    Jan 2010
    Posts
    8
    Post Thanks / Like
    Rep Power
    0

    Smile Question about C++ references?







    I understand what references are. They refer to a variable which you can change using a reference,but can you change a variable in a function without using a reference? The book i have doesn't go into much depth about it.

  2. #2
    Array sandun dhammika's Avatar
    Join Date
    Mar 2010
    Posts
    2
    Post Thanks / Like
    Rep Power
    0

    Default







    please don't confuse the references and pointers.
    Pointers and references are two distinct.

    for a example the bellow code demonstrates swap function
    with using pointers and references.

    Code:
    void swap(int&a , int& b)
    {
         int temp ;
         temp = a;
         a = b;
         b = temp ;
    }
    
    void swap(int *a , int *b)
    {
        int temp;
        temp = *a ;
        *a = *b;
        *b = temp ;
    }
    So using pointers you can change do the same thing.But using pointers is little bit
    dirty.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Table Question
    By shnconger in forum Web Design & Blog Discussion
    Replies: 0
    Last Post: 11-09-2011, 11:15 PM
  2. PHP tag question
    By plaqichczj in forum Programming
    Replies: 0
    Last Post: 11-06-2011, 10:02 PM
  3. Question about php edidtors
    By plaqichczj in forum Programming
    Replies: 0
    Last Post: 10-27-2011, 11:38 PM
  4. .htaccess Question
    By plaqichczj in forum Programming
    Replies: 0
    Last Post: 10-08-2011, 08:23 PM
  5. web programming question.
    By Gtoo in forum Programming
    Replies: 1
    Last Post: 01-17-2010, 07:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •