A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
int *p and int* p compile to the same thing. The compiler does not care about your spacing. But the grammar cares, and the grammar says the * binds to the declarator, not the type specifier. This matters when you declare multiple variables on one line. int* a, b; does not declare two pointers. It declares one pointer and one int. This has confused beginners since the 1970s and it will confuse you too unless you internalize the rule.
#include <stdio.h>int main(void) {int *a, b;int* c, d;printf("sizeof(a) = %zu (pointer)\n", sizeof(a));printf("sizeof(b) = %zu (int)\n", sizeof(b));printf("sizeof(c) = %zu (pointer)\n", sizeof(c));printf("sizeof(d) = %zu (int)\n", sizeof(d));return 0;}
Both lines declare one pointer and one int. The spacing is cosmetic. The * attaches to the variable name in the grammar. int* c, d parses as (int*) c, (int) d. Not (int*) c, (int*) d. If you want two pointers, you need int *c, *d or two separate declarations.
Declare one variable per line. int *p; int *q; No ambiguity. No multi-declaration traps. The extra lines cost nothing. The clarity is worth it. This is the style used in the Linux kernel, in BSD codebases, and in most security-critical C projects. The one-variable-per-line rule eliminates an entire category of misreading.
This is a style issue with correctness implications. The compiler is happy either way. The next human reading your code might not be. One variable per line. Pointer star next to the name. Move on. Next: NULL pointers, the sentinel value that prevents a thousand segfaults.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.