-1

I've been learning C, and there's something about type declarations that still isn't clear to me, and I haven't found a great answer yet. From what I'm seeing, the exact ordering of the type and modifiers doesn't seem all that important from a practical, pragmatic standpoint. For example, these lines below are all essentially equivalent (right?):

const int * np;
int const * np;
int * const np;

My question is, are these actually completely equivalent in the eyes of (say) the compiler, and/or are there some differences in them that could become important in some case(s)?

In reading through other's code, I find that there is a lot of variation in how people prefer to do these declarations, and I'm just trying to be sure I'm not missing something important.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
Nate
  • 1,253
  • 13
  • 21
  • 1
    Seems my question is a duplicate. I should say I couldn't find that answer using Google or SO's own search bar, so hopefully my question is a little more search friendly and will lead others to those other answers. – Nate Sep 29 '19 at 18:00

1 Answers1

1

The first two are the same, but the third is not.

In the first two cases, np is a pointer to a const int. So you can change np but not *np.

In the third case, np is a const pointer to int. So np cannot be changed but *np can.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
dbush
  • 205,898
  • 23
  • 218
  • 273