+ 4
How is the output 'a'
I was asked this question in Solo learn Char *ptr ="abcde"; Count<<*ptr++; Ok I guess I haven't learn this yet
6 ответов
+ 6
By the way, it is cout<<*ptr++;
And that is because the pointed address is defaulted at array index 0, so when post increment is applied, you print the object in the current address before moving on to the next address.
+ 6
Ptr is pointing to the 'a' character in the string and that's what should get printed. The increment to the pointer happens later as it is a post increment. BTW it's cout not Count.
+ 3
Because pointer is store the address of first index of the array or string.and increment operator (++) increase the address of the pointer and pointer point to next index of the array or string.
+ 2
Yeah may be I thought syntax for declaration of pointer is something like this data type *name
0
Pointer allways points on first value in a list if u do cout<<*++ptr; it will show 'b' but when u do cout<<*ptr++; it shows 'a' you can also follow code with cout<<*ptr; on the next line, and it will print 'b'
0
Becauae of the pointer is post increment it will print the first element in the array i.e., ' a ' and then incremented by 1 then it will print 'b' and so on.....