Thread: modified

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    77

    modified

    how do i change the fuction below using pointer method to return back the value of x and y?

    Code:
    void exchange(int x,int y)
    {
       int temp;
       temp = x;
       x = y;
       y = temp;
     return ;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You would change the parameters x and y such that they are pointers to int rather than int variables. Then you make the corresponding changes to the implementation of the function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by archriku View Post
    how do i change the fuction below using pointer method to return back the value of x and y?

    Code:
    void exchange(int x,int y)
    {
       int temp;
       temp = x;
       x = y;
       y = temp;
     return ;
    }

    Code:
    void exchange(int  *x,int  *y)
    {
       int temp;
       temp = *x;
       *x = *y;
       *y = temp;
    }
    Call the function like this exchange(&a,&b).
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's a hint: When someone asks how to do something, don't do the whole thing for them. Tell them how, they can try it, and if they have problems, they can post their code and people can explain the process again.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is Text Modified in Edit Control
    By anon in forum Windows Programming
    Replies: 1
    Last Post: 05-21-2006, 01:33 PM
  2. Date Last Modified
    By magic.mike in forum Windows Programming
    Replies: 5
    Last Post: 09-23-2005, 05:13 AM
  3. Modified clrscr function
    By GaPe in forum C Programming
    Replies: 2
    Last Post: 06-01-2002, 04:07 AM
  4. Last modified date?
    By Hoxu in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2001, 12:32 PM