1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Swapping

Discussion in 'C' started by inspiration, Mar 1, 2010.

  1. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I'm newbie in C and just learning about pointers and having problem with a program code.
    That was, SWAPPING using pointers.
    Can anyone please tell me that?
    :D
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Here is the code...
    Code:
    #include<stdio.h>
    #include<conio.h>
    void swap(int*, int*);
    void main()
    {
    int i,j;
    clrscr();
    printf("Enter the value of i and j respectively:");
    scanf("%d %d",&i,&j);
    swap(&i,&j);
    printf("%d %d",i,j);
    getch();
    }
    
    void swap(int *i, int *j)
    {
    int k;
    k=*i;
    *i=*j;
    *j=k;
    printf("%d "%d",*i,*j);
    }
    
     
  3. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Pankaj!
    Too fast to help me...
    :)
     
  4. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:

Share This Page