Please explain me this C++ output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Please explain me this C++ output

Why does this code output "Ella"? #include <iostream> using namespace std; int main() { cout << 4 + "UmbrElla"; return 0; }

12th Jan 2019, 6:48 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
4 Answers
+ 5
I Understand. Practically, does this code add 4 to the address of first character of the string?
12th Jan 2019, 7:34 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
four steps to the right and output the rest which is Ella
15th Jan 2019, 10:16 AM
‎‏‪Milla
+ 1
Think "UmbrElla" with a string in mind What's a string in C++? A char* You're doing a +4 on a char*, that's a pointer so you're doing maths on pointer So you're printing the char* starting 4 case after the start
21st Jan 2019, 11:01 PM
Abel Louis
Abel Louis - avatar
+ 1
yes we can use addition and subtraction on pointers.when we do that we are changing the pointers value from one address to another address.since computer address is sequential when we use addition +1 it's goes to the next memory address.
22nd Jan 2019, 3:58 AM
‎‏‪Milla