+ 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; }
4 Antworten
+ 5
I Understand. Practically, does this code add 4 to the address of first character of the string?
+ 1
four steps to the right and output the rest which is Ella
+ 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
+ 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.