W
Wonder
Hello,
I'm confused by the pointer definition such as int *(p[3]);
It seems if the parenthesis close p[3], it defines only 3 integers. The
star
is just useless. It can be showed by my program:
int main()
{
int *(p[3]);
// cout << *p[0] << "\t" << *p[1] << "\t" << *p[2] << endl;
cout << &p[0] << "\t" << &p[1] << "\t" << &p[2] << endl;
cout << p[0] << "\t" << p[1] << "\t" << p[2] << endl;
}
The program can be compiled on cygwin linux by g++ and run, the output
is:
0x22efb0 0x22efb4 0x22efb8
0x76c 0xffffffff 0x22efc8
If you delete the * in the definition, define int (p[3]); the second
line
will be:
1900 -1 2289608
Which is exactly the decimal numbers of the the previous program.
The second line is comment-out, coz it'll be core dumped if you want to
get
the content of the pointer.
Could someone explain what's going on here? Thanks.
I'm confused by the pointer definition such as int *(p[3]);
It seems if the parenthesis close p[3], it defines only 3 integers. The
star
is just useless. It can be showed by my program:
int main()
{
int *(p[3]);
// cout << *p[0] << "\t" << *p[1] << "\t" << *p[2] << endl;
cout << &p[0] << "\t" << &p[1] << "\t" << &p[2] << endl;
cout << p[0] << "\t" << p[1] << "\t" << p[2] << endl;
}
The program can be compiled on cygwin linux by g++ and run, the output
is:
0x22efb0 0x22efb4 0x22efb8
0x76c 0xffffffff 0x22efc8
If you delete the * in the definition, define int (p[3]); the second
line
will be:
1900 -1 2289608
Which is exactly the decimal numbers of the the previous program.
The second line is comment-out, coz it'll be core dumped if you want to
get
the content of the pointer.
Could someone explain what's going on here? Thanks.