0

I am new to C. I read that we can define a pointer like

int *pointername

However, I also read a piece of coding like the following

int * pointername

So my question is whether the blank is optional in this case?

More broadly speaking, could anyone summarize how blanks are used in C, please? For example, are two blanks the same as one blank? When is a blank necessary and when is it optional? ...

As pointed out in a comment, I am also asking for general question on treatment of blanks in C. So please do not close this question. Thank you.

LaTeXFan
  • 1,136
  • 4
  • 14
  • 36
  • 2
    I think it is the wrong place to ask (because we cannot teach you C in a few paragraphs). You need to read a good C programming book, and look at some good [C reference documentation](http://en.cppreference.com/w/c) – Basile Starynkevitch Nov 19 '16 at 10:10
  • @BasileStarynkevitch Can you suggest a good C programming book, please? Please know that I am new to C and previously had some experience in R. Thanks. – LaTeXFan Nov 19 '16 at 10:12
  • Well neither of those has the asterisk at the correct position. Yes, come at me! – DeiDei Nov 19 '16 at 10:12
  • Book recommendations are also off-topic. http://www.cprogramming.com/books/ritchie.html ; but I also recommend https://mitpress.mit.edu/sicp/ (which is about programming, not about C) – Basile Starynkevitch Nov 19 '16 at 10:14
  • 4
    @DeiDei: this is only your opinion (and I disagree with it). And it is a matter of style. From the standard [C99](https://en.wikipedia.org/wiki/C99) perspective, both piece of code are ok (but **both lack a final semicolon**) – Basile Starynkevitch Nov 19 '16 at 10:17
  • 2
    @LateXFan: see also (and download) [n1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) which is *very close* to the C11 standard. – Basile Starynkevitch Nov 19 '16 at 10:19
  • 1
    I would've opted for re-openning. The question is not about which part of declaration an asterisk is but about treatment of white-space in C. – Dima Chubarov Nov 19 '16 at 10:29
  • @DmitriChubarov Second that. – LaTeXFan Nov 20 '16 at 01:06
  • @BasileStarynkevitch What about the more general question on blanks? – LaTeXFan Nov 20 '16 at 01:07
  • @LaTeXFan Perhaps you could stress that the case of the treatment of `*` in declarations is just one example. Other interesting cases might be empty macro definitions, e.g. `#define BLANK` – Dima Chubarov Nov 20 '16 at 08:18
  • @DmitriChubarov Could you edit my question, please? I am not aware of empty macro. I am only getting started with C. Thank you. – LaTeXFan Nov 20 '16 at 08:55

0 Answers0