CCoding Style - Indent to show structure

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Indent to show structure

A consistent indentation style is necessary to make a program’s structure self-evident.

*i=‘\0; return(‘\n’);

Reformatting improves it somewhat:

for( n++; n < 100; field[n++] = ‘\0)
*i = ‘\0;
return (‘\n’);

Even better is to put the assignment in the body and separate the increment, so the loop takes a conventional form and is thus easier to grasp:

for( n++; n < 100; n++)
    field[n] = ‘\0;
*i = ‘\0;
return ‘\n’;