Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

where do you put the * in type declarations?

Name: Anonymous 2011-08-01 13:57

a) int *p;
b) int* p;
c) int * p;
d) int*p;

c) here

Name: Anonymous 2011-08-02 14:51

    int *p;
//      ^--------(*p) is of type int


    int *const p[];
//      (    ^   )----Read this like a statement.
//   ^----------------The returned value is of type int.[/code]
If you index p as an array you get a value, which if dereferenced as a constant pointer will return an int.


This is how it is implemented. If we wanted to group the pointer and array declaration with the type, there would be a much more natural way:
(const* int)[] p; //p is an array of constant pointers to int

But someone decided that we do it the other way and we have  for the last 30 years. Writing int* p only leads to confusion because it really means int(* p).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List