+ 1
Can any one explain what is happening here?
#include <iostream> using namespace std; int main() { int *p; (*p)++; cout<<sizeof(p)<<" "<<sizeof(*p); return 0; } // Output : No output
3 Respostas
+ 3
Your code seems to miss some lines. I amended it and wrote some comments. Hope that helps to understand it.
#include <iostream>
using namespace std;
int main() {
int a = 0; //declare & initialize a to 0
int *p; // declare a pointer
p = &a; //initialize pointer to point to address of a
(*p)++; // dereference pointer with (*p) so it accesses the value of a
cout<<sizeof(p)<<" "<<sizeof(*p)<<" "<<*p<<" "<<p;
return 0;
}
+ 1
~ swim ~
Yes you are right...
#include <iostream>
using namespace std;
int main() {
int *p;
p = new int;
(*p)++;
cout<<sizeof(p)<<" "<<sizeof(*p);
delete p;
return 0;
}
// Output : 8 4
Now its working fine...