+ 7
🙋🏆Question🏆🙋 Please help me to understand this code
Hey hi guys I know that when you assign or declare a chracter in c or cpp it get stored with its ASCII value just as 'A' has ASCII value of 65 and so on...... in this code I was trying to print the ASCII values where I got stuck at a line ........ Please help me to understand how the characters , string are stored in memory as well as what get happen if I wrote 'ab' instead of 'a' in cpp.. please help me to understand.... https://code.sololearn.com/cvpqN4tk267l/?ref=app
8 odpowiedzi
+ 16
×256 🤔🤔🤔
+ 10
This is whats happening with "ab"
"a" * 256 + "b" = 24930
this happends everytime when theres more then one char inside " " if you want to add them seprate do this
cout << "ASCII Value of ab is " <<int ('a'+'b')<<endl;
+ 3
😮
sorry
and Thank you very much for help
+ 2
just one doubt again
why is it
multiplied by 256 and then adding ascii of b
+ 1
code prints when I write
cout << "ASCII Value of ab is " <<int('ab')<<endl
output : ASCII Value of ab is 24930
what about this 24930 how does it come..?
I respect your answer you are adding the ASCII values of 'a' and 'b' which are 67 and 68 if I am not wrong
but I want to know about the 24930 how does it come
and meanwhile I was thought that if you write 'ab' that is two characters in single quotes it will give you error because single characters has there own ASCII values
it is not giving me the error too, it accepts 2 characters in single quotes
please help me about it
how can it accept 2 characters in single quote and if it can how will it stored them in memory.....
+ 1
once again thanks for your help @David
please help me to understand this ....
+ 1
why to multiply by 256...???
+ 1
I want to know the same