void main()
{
char s[]="string";
char *sp=s;
while(*sp!='\0')
{
cout<<*sp;
sp++;
}
}
SHOWS ME: string
but if i replace cout<<*sp with cout<<sp ,i have
stringtringringingngg..why is this decremented crap coming ,what is the difference when i dont use the * sign??
plz help
If you remove it, you'll have the pointer itself. When you pass a pointer to char to <<, it will think that it's a C style string and print it as that. This is the reason of the weird output
When you use *sp, cout prints content of pointer's actual position. When you use sp, cout prints content of whole thing, that was attributabled to pointer. So, if you attributable array of chars "string" it prints everything from pointer's current position to end of adresses attributabled to it.