c++ - 无法将 int 转换为 int *

标签 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;

     }
}

//我得到 .. 无法将 int 转换为 int * ...

谁能告诉我为什么会这样。以及如何解决 问候。

希望得到快速和积极的回应。

最佳答案

您对 swap() 的调用应包含 & 符号:

swap(&a,&b);

swap 需要指向 int 的指针,因此您需要获取 ab 的地址将它们传入。

关于c++ - 无法将 int 转换为 int *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3653896/

相关文章:

c++ - 文字运算符模板在 GCC 4.8 中不起作用

c++ - "Expression: vector iterator not deferencable"运行时错误

c++ - 将 NULL 视为 QByteArray 中的字符

c - 如何通过 minicom 或屏幕与 pty 通信?

c - 为什么我的程序的输出没有复制所需的输出?

c++ - 增加 X11 R6 中的字体大小和属性

c++ - 为什么函数重载有歧义,而模板重载却没有歧义?

c语言printf float错误

c++ - Arduino c语言清空一个字符串的方法

c - malloc C 之后写入数组时出现问题