Does this offer declare two pointers or a pointer and an object? Is this true for any type of variable?

int* x, y;

    2 answers 2

    int* x, y; - pointer x and integer variable y .

    * refers to a variable , not a type .

    Declare a type using typedef (or in C ++ using using ) - then another thing:

     typedef int * pint; pint x, y; 

    Here both x and y are pointers to int .

    • one
      Never do typedef int * pint; in C. - 0andriy
    • one
      @ 0andriy <irony_mode> Win API does not agree with you! </ Irony_mode> - Monah Tuk
    • @ 0andriy Share how it should be done then. - Harry
    • @ 0andriy, why? I remember about define, but what’s wrong here? - Qwertiy
    • @Harry, use explicitly. It makes sense for opaque pointers , for POD this makes the code error prone (remember for example that implicit casting type * in void * works), the const qualifier is bad with that. You can read stackoverflow.com/questions/3781932 with comments and answers, then follow the link there. - 0andriy

    Pointer and non pointer.
    Therefore, it is customary to write an asterisk in front of the variable name, not in front of the type.

    http://ideone.com/oVvCU2

     #include <stdio.h> int main() { short *a, b; printf("%zu %zu\n", sizeof a, sizeof b); return 0; } 
    • Who accepted ???? - αλεχολυτ
    • @alexolut, everyone?) - Qwertiy
    • one
      by no means. It is generally accepted to write every identifier on a new line with a type. - αλεχολυτ
    • @alexolut, firstly, does not interfere with one another - it is quite possible to write one ad on a line and at the same time put an asterisk in front of the name. And secondly, I would argue that it is really customary to write one per line. - Qwertiy
    • argue :) but better in chat - αλεχολυτ