struct dirent* entity i runned the both codes and complair didn't give any error. if both of these code true why people prefer struct dirent* entity it's quite confused ...
@baduymus - you need to explain your problem more accurately. You probably need a better translator. "Both codes" implies two codes, neither of which we can see. "Complair"??? - compiler ?
why people prefer struct dirent* entity
Not sure where you are getting your statistical data on that from.
Any of dirent* entity
dirent *entity
dirent * entry
dirent*entry
could equally well be used, according to people's taste and the time of day.
A "typical C programmer" writes "int *p;'' and explains it "*p is what is the int" emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar.
A "typical C++ programmer" writes "int* p;" and explains it "p is a pointer to an int" emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well.
The critical confusion comes (only) when people try to declare several pointers with a single declaration:
...
Stick to one pointer per declaration and always initialize variables and the source of confusion disappears.
I think the one-variable-per-declaration convention has a lot of merit even without pointers. It makes the code easier to read and it also makes the code easier to work with, e.g. if I need to (re)move one of the variables or add another one.
The advantage is similar to the convention of always using { and } with loops and if statements even when not needed because it makes it easier to add more statements later and the consistency makes the code easy to read.
The only place I would consider declaring more than one variable in the same declaration would be a for loop.
Maybe I would have felt differently if I had been programming in old C where I would have had to declare all variables at the beginning of the function before having a sensible value to initialize them with, but I think the points I made above hold true even here to a large extent especially if I would want to put a comment on each variable to explain where and what it's used for (something that is less obvious if the declaration is located far from where the variable is used).
And for anyone that feels it's tedious to retype the name of the datatype (and also the "struct" keyword in C) and possibly other qualifiers like const I should perhaps mention that I don't actually retype lines like that. I press Ctrl+D to duplicate the line and then I just change the variable name. To remove a declaration I just place the caret at the end of the line and press Shift+Home followed by Delete. Easy, peasy! :)