+ 1

Plz explain 7th line of code and hence the output?

c++ challenge question. https://code.sololearn.com/cu43n6fXgk38/?ref=app

20th Dec 2021, 9:06 AM
gaurav kumar
gaurav kumar - avatar
5 odpowiedzi
+ 4
gaurav kumar Actually here ASCII value is subtracting not character A character can assign to int data type but when you print that you get ASCII value. Try this: int a = 'a'; cout << a;
20th Dec 2021, 9:16 AM
A͢J
A͢J - avatar
+ 3
gaurav kumar c = s[3] = a On line number 7 there is ++c so now c would be b as it is increasing ASCII value of a so next character is b ++c = b Now s[1] is b so a would be 0
20th Dec 2021, 9:11 AM
A͢J
A͢J - avatar
+ 3
gaurav kumar ASCII value of a = 97 ASCII value of b = 98 So here ++c would be 98 but c is a char so it will print b if you do int a = 'a' then you will get cout << a; as 97
20th Dec 2021, 9:14 AM
A͢J
A͢J - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ plz tell how we can subtract two characters.
20th Dec 2021, 9:14 AM
gaurav kumar
gaurav kumar - avatar
0
char is an integer data type, we can subtract them. in your example: ++c = s[1] = 'b' a = ++c-s[1] = 'b' - 'b' = 98 - 98 = 0
21st Dec 2021, 9:58 AM
Bob_Li
Bob_Li - avatar