Will this correctly declare one an integer and another as an pointer to an integer or will this just cause problems?
int *countPtr, count;
Will this correctly declare one an integer and another as an pointer to an integer or will this just cause problems?
int *countPtr, count;
It is a valid declaration, it will compile.
However, it can lead to confusion, so it's safer to declare it separately:
int count;
int *countPtr;
For increased readability, you can keep in mind this simple rule:
Don't mix types in one declaration.
You don't want to see nightmares like int x, y, *p, t[10], i, f();
.
Will this correctly declare one an integer and another as an pointer to an integer?
Yes.
Will this just cause problems?
Yes. Declarations of multiple types on a single line (especially when pointers are involved as in your example) is heavily discouraged, for the obvious readability/maintenance issues.
It is completely fine.
countPtr
will be a pointer to intcount
will be just regular intNo, this is a valid statement and will work as expected.
Writing
int* countPtr, count
would do the same thing, but can lead to confusion.
Will this correctly declare one an integer and another as an pointer?
Absolutely.
will this just cause problems?
Programically speaking, No. Readability-wise, Depends on how you interpret the declaration int *countPtr, count;
. I read it as "integer-holder countPtr and integer count". So no problems for me.