Thread: Working with functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    11

    Working with functions

    I don't know if this is a suitable subforum to talk about the the following
    Suppose we have a function called foo() which receive two arguments foo(a,b) and swap them.

    Code:
    int n1 = 2, n2 = 33;
    // before swap
    print n1, n2;
    foo(n1,n2);
    // after swap
    print n1, n2;
    
    // the function
    foo(a, b) {
     int temp = a;
     a = b;
     b = temp;
    }
    The expected output:
    >> 2 33
    >> 33 2

    Is that right or de we have to work with "pointers"?
    Last edited by themsaman; 03-14-2010 at 06:50 AM. Reason: add notification

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static functions.... why?
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2007, 08:06 PM
  2. Static member functions more efficient?
    By drrngrvy in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2006, 07:07 AM
  3. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  4. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  5. Functions are not working
    By founder247184 in forum C++ Programming
    Replies: 0
    Last Post: 11-29-2002, 04:00 PM