Jump to content

Recommended Posts

Posted

#include <stdio.h>
void swap(int *x, int *y);

int main(void)
{
  int i, j;

  i = 10;
  j = 20;

  printf("i, j: %d %d\n", i, j);

  swap(&i, &j); /* i j */

  printf("i, j: %d %d\n", i, j);

  return 0;
}

void swap(int *x, int *y)
{
  int temp;

  temp = *x;  /* save x */
  *x = *y;    /* move y -> x */
  *y = temp;  /* move x -> y */
}

swap(&i, &j) - Call

void swap(int *x, int *y) - In the function

You cannot use the ByRef in the call

Posted

That is using pointers.

* is symbol for pointer

& is symbol for by reference

I wont dare go into the difference at my level, but I'm quire sure about this.

#include <stdio.h>
void swap(int &, int &);

int main(void)
{
  int i, j;

  i = 10;
  j = 20;

  printf("i, j: %d %d\n", i, j);

  swap(i, j); /* i j */

  printf("i, j: %d %d\n", i, j);

  return 0;
}

void swap(int &x, int &y)
{
  int temp;

  temp = x;  /* save x */
  x = y;    /* move y -> x */
  y = temp;  /* move x -> y */
}

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...