Jump to content
Sign in to follow this  
AZJIO

AutoIt3 & С++

Recommended Posts

AZJIO

#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

Share this post


Link to post
Share on other sites
JohnOne

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.

Share this post


Link to post
Share on other sites
Richard Robertson

The difference between & and * is that & passes the address of the variable in the form of a pointer to data. * passes an address to data.

It gets especially confusing when both & and * describe the same variable.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.