Below is the code for which I want to know the answer to 2 questions in the side comment. Please help me
#include<iostream>
using namespace std;
int main()
{
char *p="Hello";
cout <<*p; //gives H
cout <<*(p++); //also gives H.Why?
cout <<*(p++); //gives e.
cout <<*(p++); //gives l.
cout <<*(p++); //gives l.
cout <<*(p++); //gives o.
cout <<*(p++); //gives no output.Why? It should give some garbage value!
}
*(p++) gives 'h' because you first ask the value and than increment the position of your pointer and it the same thing in the last line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With