在这个程序中,我创建了两个指针(a,b),指向x和y的内存地址.在我创建的函数中,它应该交换a和b的内存地址(So b = a和a = b).当我编译它时给我一个错误(从'int'到'int*'的无效转换)这是什么意思?我正在传递一个指向该函数的指针,还是将其作为常规int读取?
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
void pointer(int* x,int* y)// Swaps the memory address to a,b
{
int *c;
*c = *x;
*x = *y;
*y = *c;
}
int main()
{
int x,y;
int* a = &x;
int* b = &y;
cout<< "Adress of a: "<<a<<" Adress of b: "<<b<<endl; // Display both memory address
pointer(*a,*b);
cout<< "Adress of a: "<<a<<" Adress of b: "<<b<<endl; // Displays the swap of memory …
Run Code Online (Sandbox Code Playgroud)