C programming Basic

#include <iostream>

using namespace std;
int main ()
{
cout << 5+"My name is Dwe";
return 0;

}


Please explain it with giving output
thanks
Last edited on
What kind of object is returned by "My name is Dwe"? A pointer. Now learn about pointer arithmetic.

Actually I am basic learning c programming . I just started . But as we see in c++ programming cout prints string in " " field . But is giving output >> me is Dwe . Why it is so :( . plz help
No, cout does not print everything in the " " field. cout doesn't know what a " " field is. In your code, you are NOT passing the " " field to cout. You are passing a pointer.

This: 5+"My name is Dwe" gives a char pointer. The char pointer is gives does NOT point at the 'M'.

You currently do not understand what a pointer is, so telling you that 5+ a pointer gives another pointer that points to a poisition in memory (5*size of object being pointed at) isn't going to be much use to you.

Learn about pointers.
Thank you very much Moschops..

Basically you're pointing to a position where "my name is dwe" is stored but by using +5 you're pointing 5 memory slots after this, which is why it starts 5characters into your message

I hope that's a much simpler way of explaining this, for now of you're only just starting c then don't worry about pointers, just think of it outputting "text" or variables
Thanks :)
If anyone's in UK and on skype fairly often i'd be happy to discuss problems and help out in anyway i can (and ask a few questions myself)

benjamin.james.fisher OR SatsumaBenji
Topic archived. No new replies allowed.