判斷下面程式碼中的運算式,運算子 +,為何種資料型態加法運算?
char a='A';
int b=3;
float c=2;
double d=1;
c = a + 'B';
b = b + 1;
b = b + 1.0;
d = (c + 9)/3;
d = (c + 9)/3.0;
c = c + d;
d = a + b * c;
c = a + 'B'; // int +
b = b + 1; // int +
b = b + 1.0; //double +
d = (c + 9)/3; //float +
d = (c + 9)/3.0; //double +
c = c + d; // double +
d = a + b * c; //float +
下列程式碼 cout 螢幕會出現何值?
int a=21, b=3;
a = (++b)*2;
cout << a << endl;
b *= 5;
cout << b << endl;
a = b % a;
cout << a << endl;
a = (b –= 4)*2;
cout << a << endl;
下列程式碼 cout 螢幕會出現何值?
(了解布林型態之整數運算)
bool a=false;
int b=1;
a = a+b;
cout << a << endl;
b += a;
cout << b << endl;
cout << false << endl;
int a = 3 , b = 2;
cout << a << ++a << endl;
cout << a+b << (b += ++a) << ++a << endl;
cout << a << b << (a = b = 2) << (a = b = 3) << endl;
cout << a << (b -= a++) << a++ << endl;