0
I cant understand why result is that
#include <iostream> using namespace std; int main() { char a= 'b'; char b= 'a'; cout << b%a; return 0; } why output is 97 ?
5 odpowiedzi
+ 2
cout << 'a' % 'b'; // 97
// same as:
cout << 97 % 98; // 97
// because:
cout << (int) 'a'; // 97
cout << (int) 'b'; // 98
// or:
cout << (char) 97; // 'a'
cout << (char) 98; // 'b'
The numbers you get are the positions of these chars in the ASCII table.
+ 2
Because characters are threatened as integers while calculating with them.
+ 1
to see ASCII codes:
#include <cstdio> // for printf()
int main(){
for(int i = 1; i < 256; ++i)
printf("%i = %c\n", i, i);
}
0
isnt there an easy way to know ASCII numbers ?