modified

This is a discussion on modified within the C Programming forums, part of the General Programming Boards category; how do i change the fuction below using pointer method to return back the value of x and y? Code: ...

  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
    21,598
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 11:32 AM

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