+ 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

5th Nov 2017, 2:19 PM
Prathamesh Joshi
Prathamesh Joshi - avatar
8 Answers
+ 16
×256 🤔🤔🤔
5th Nov 2017, 4:16 PM
Harshad Gare
Harshad Gare - avatar
+ 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;
5th Nov 2017, 2:26 PM
D_Stark
D_Stark - avatar
+ 3
😮 sorry and Thank you very much for help
5th Nov 2017, 3:00 PM
Prathamesh Joshi
Prathamesh Joshi - avatar
+ 2
just one doubt again why is it multiplied by 256 and then adding ascii of b
5th Nov 2017, 3:02 PM
Prathamesh Joshi
Prathamesh Joshi - avatar
+ 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.....
5th Nov 2017, 2:38 PM
Prathamesh Joshi
Prathamesh Joshi - avatar
+ 1
once again thanks for your help @David please help me to understand this ....
5th Nov 2017, 3:11 PM
Prathamesh Joshi
Prathamesh Joshi - avatar
+ 1
why to multiply by 256...???
5th Nov 2017, 3:45 PM
Rohit Jadhav
+ 1
I want to know the same
5th Nov 2017, 4:01 PM
Prathamesh Joshi
Prathamesh Joshi - avatar