I wrote the following code
#include <iostream>
#define circleArea(r) (3.1415*r*r)
int main() {
std::cout << "Hello, World!" << std::endl;
std::cout << circleArea('10') << std::endl;
std::cout << 3.1415*'10'*'10' << std::endl;
std::cout << 3.1415*10*10 << std::endl;
return 0;
}
The output was the following
Hello, World!
4.98111e+08
4.98111e+08
314.15
The doubt i have is why is 3.1415 * '10'*'10'
value 4.98111e+08
. i thought when i multiply a string by a number, number will be converted to a string yielding a string.Am i missing something here?
EDIT: Rephrasing question based on comments, i understood that single quotes and double are not same. So, '1' represents a single character. But, what does '10' represent
'10'
is a multicharacter literal; note well the use of single quotation marks. It has a type int
, and its value is implementation defined. Cf. "10"
which is a literal of type const char[3]
, with the final element of that array set to NUL
.
Typically its value is '1' * 256 + '0'
, which in ASCII (a common encoding supported by C++) is 49 * 256 + 48 which is 12592.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With