+ 10
[ Solved ] What is 1702063987 as output in this c++ code ??
Edited : I want explanation ( CODE 2 ) ; sample input : 4000 100 I know i have coded wrong I used ' ' instead of " " I just want to know is this(1702063987) in output of CODE 2 ??? https://code.sololearn.com/cM2VXO2j81BQ/?ref=app
11 Answers
+ 4
Mr. Rahul DM's aren't working properly for me, so contacting me there is not ideal. Anyway, regarding your message:
I think you already got a pretty sufficient answer above. Just as stated before, the resulting value is implementation-defined, but it seems GCC deals with such constants by storing the last four characters from left to right (possibly endian-dependant, I can't tell though). The integer value is just the result of interpreting the binary sequence as a natural number (which is endian-dependant, relating to my comment earlier):
'e' = 101 = 01100101
'o' = 111 = 01101111
's' = 115 = 01110011
'Pesos' => 'esos'
= 01100101 0111011 01101111 01110011
= 1.702.063.987
+ 5
Mr. Rahul As I've said in my previous reply, the value if implementation defined. Meaning that it depends on how the compiler you're using interprets the multi-character constant.
You can see an example of it from here:
https://www.viva64.com/en/b/0634/
If you don't know what multi-character constants are, you should read this:
https://en.m.wikipedia.org/wiki/C_syntax#Character_constants
Edit:
Here's a quote from the Wikipedia page
> Multi-character constants (e.g. 'xy') are valid,
> although rarely useful — they let one store
> several characters in an integer (e.g. 4 ASCII
> characters can fit in a 32-bit integer, 8 in a 64-bit
> one).
+ 4
From what I've read, it's called a multi character literal. It is of type int with an implementation defined value.
More info here:
-https://stackoverflow.com/q/3960954
-https://en.cppreference.com/w/cpp/language/character_literal
+ 3
Single quotation marks in C++ ( ' ' ) are used for char data-types.
While, double quotation marks (" ") are used for string data-types.
+ 3
+ 2
Why there are numbers as output in code 2 《 Nicko12 》
+ 2
🤣🤣🤣 single quote and double quotes different
+ 2
Ok I did that difference with my self
Altero (Inactive) I didnt get about the numbers as output in CODE 2
+ 2
《 Nicko12 》 you are completely right
Single quote for a single character
Double quote for one and more characters
https://code.sololearn.com/cv8LJmlSJ0oH/?ref=app
+ 2
Thanks Shadow sir for your help
+ 1
#include <iostream>
using namespace std;
int main() {
int x;
int y;
cin >> x >> y;
if (x / 50 > y) {
cout << 'Dollars';
}
else {
cout << 'Pesos';
}
return 0;
}
嶺上開花
In above code i knew i made mistake of using ' ' instead of " "
So after my code execution the ide has to direct show me that error and its showing the error
but my problem is ; It's showing a random number like 1702063987 with
input
4000
100
what i would say about this number that is showing as output ( Run Code 2 ) ??