qq_43473753
Yes ,I can !
2019-01-12 17:02

请问ap =( int *) &a;这是什么意思?ap++;bp++;为什么要用这两个语句?为什么a,b两个值可以交换?

  • c++

#include "pch.h"
#include
using namespace std;
int main()
{
double a = 123.456, b = 456.789;
int ap, *bp;
ap =( int *) &a;
bp =(int
)(&b);
cout << "a=" << a << "b=" << b << endl;
*ap = (*ap) ^ *(bp);
*bp = (*ap) ^ (*bp);
*ap = (*ap) ^ (*bp);
ap++;
bp++;
*ap = (*ap) ^ *(bp);
*bp = (*ap) ^ (*bp);
*ap = (*ap) ^ (*bp);
cout << "a=" << a << "b=" << b << endl; cout <<*ap << *bp;
return 0;
}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答