我试图使用指针交换两个整数的值,请参阅下面的代码:
void swapArgs(int *a, int *b) {
int *temp = &b;
b = &a;
a = &temp;
printf("Swapped Arguments: A=%d, B=%d\n", *a, *b);
}
Run Code Online (Sandbox Code Playgroud)
执行printf时,结果值是巨大的数字.任何人都可以向我解释我的代码有什么问题吗?指针还是新手.
我遇到了一个我无法弄清楚的问题,我对c ++仍然很新.这是一段代码:
#define secondsInHour 3600;
#define secondsInMinute 60;
using namespace std;
int main()
{
int totalSeconds;
int convertedHours;
int convertedMinutes;
int convertedSeconds;
cout << "Enter time in seconds: ";
cin >> totalSeconds;
cout << endl;
convertedHours = totalSeconds / secondsInHour;
convertedMinutes = (totalSeconds - (convertedHours*secondsInHour))/secondsInMinute; //D
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时,我收到以下错误:预期')'有人能解释一下吗?错误指的是倒数第二行.
编辑:我正在使用Visual Studio 2015.抱歉,我指的是错误的行.产生错误的行是"convertedMinutes = ...."