### Tip 5: Initialize wherever the first use may be

Part of a series of tips on POSIX and C. Start from the tip intro page, or get 21st Century C, the book based on this series.

level: still pretty basic
purpose: not think about declarations so much

I see code like this pretty often:

int main(){
int i;
double ratio, denom;

denom=7;
head = "There is a cycle to things divided by seven.";
for (i=0; i< 10; i++){
ratio = i/denom;
printf("%g\n", ratio);
}
}


We have three or four lines of introductory material (I'll let you decide how to count the white space), followed by the routine.

This is somewhat a matter of style, but I think this looks archaic, and I've heard from a few folks who learned to code via untyped scripting languages for whom the introductory declarations are a direct and immediate turn-off. Variables still have to have a declared type, but here's how I'd write the code to minimize the burden:

int main(){
double denom=7;
char *head = "There is a cycle to things divided by seven.";