Re: question about pointer define



Thanks a lot for your kind reply.

Now the problem goes to the difference between
int (*p)[3];
int *p[3];
int *(p[3]);

As you said, the second and the third are same. You are right, for
both, the *p[i] will give a core dump. However, the first one just give
the values of the elements, even though I didn't initialize anything.

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 output is:
440 -1869574000 -1869574000
0x6101cf3e 0x6101cf4a 0x6101cf56
0x6101cf3e 0x6101cf4a 0x6101cf56

Another strange thing is the second line and third line are same in
this case.

.



Relevant Pages

  • Re: Simple output problem
    ... > There is no need to initialize c, but if you wanted to, you would use ... int main ... divv.c:5: warning: statement with no effect ... Prev by Date: ...
    (comp.lang.c)
  • Re: OleDbDataAdapter.Fill(DataTable)
    ... This is strange. ... When I use the .Filloverload the DataTable is ... > int j = adp.Fill; ... Prev by Date: ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Object "Literals"
    ... > I want to initialize the values of rects as follows: ... So if you use Rectangle.ctor(int, int, int, int) you avoid the two "new" on ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: #define ARR_SIZE sizeof(arr)/sizeof(arr[0])
    ... Basically you need to initialize i to 0. ... Soo, ... Also ensure that main has a int return type. ... Prev by Date: ...
    (comp.lang.c)
  • [PATCH 4/7] rename locking functions - convert init_MUTEX* users, part 2
    ... struct apple_thermal_info *info; ... int __init attach_aci_rds ... /* initialize structs / fill in defaults */ ...
    (Linux-Kernel)