Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot convert int to int *

Tags:

c++

c

#include "stdio.h"
#include "conio.h"

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

void main()
{
int a=10,b=20;
swap(a,b);
printf("value of a=%d and b=%d");
getch();
}

void swap(int *x,int *y)

{
  if(x!=y)
     {
      *x ^= *y;
         *y ^= *x;
         *x ^= *y;

     }
}

// I'm getting .. cann't convert int to int * ...

can anybody tell me why so . and how to solve it regards.

hoping for quick and positive response.

like image 265
Vishwanath Dalvi Avatar asked Nov 29 '22 18:11

Vishwanath Dalvi


1 Answers

Your call to swap() should include ampersands:

swap(&a,&b);

swap is expecting pointers to int, so you need to take a and b's addresses when passing them in.

like image 93
Graham Perks Avatar answered Dec 15 '22 14:12

Graham Perks