when i just declare an integer or other variable, no memory is allocated to it. So, then if i do cout for that variable, what exactly happens?, is there any garbage memory stored in that identifier? (i think not, coz after running the program it would have given a garbage value.)
Memory is allocated when you declare it. Perhaps some compiler optimizations would get rid of any unused variables, but they'll most likely give you just warnings. The reason you get "garbage values" is because you never assigned a value to that memory, so whatever was there when it was allocated is still there.
This is different though. When you do that you are putting the memory location on the screen, not the value held in that location. It isn't junk at all.
When you do that you are putting the memory location on the screen, not the value held in that location. It isn't junk at all.
Not in this case since it is a c-string it will print the value which in this case should be garbage. Arrays of any other type would print the address of the first index.