I was woundering since my last thread, is there any exception to the semicolon at the end of every line except for when you define a function and when you start and end that function with the { } marks?
I was woundering since my last thread, is there any exception to the semicolon at the end of every line except for when you define a function and when you start and end that function with the { } marks?
It isn't that I think of it as a rule. It is because I just came from using Ruby and I am not use to the semicolon at the end of the line thing.
1. Semi-colon is not placed at the end of line, but at the end of statement. So one line can contain many statements.is there any exception to the semicolon at the end of every line
2. When you define a function body likes int foo() { stuff }.. you must not put semi-colon after (). But when you declare prototypes, you need it at the end of prototypes.
3. When you initialize array, define enum, class and so on with { at beginning, you need semi-colon after }.
4. This may not cover all usage of semi-colon, just remember in C semi-colon is as a terminator. Some language likes pascal semi-colon is as a separator.
some other "rules":
don't use semicolons after conditional statements:
if(true);//wrong
while(infile >> num);//wrong;
do use semicolons after declarations of types whether typedefs, structs, classes, functions.
Basically, no single rule, but you learn the syntax reasonably fast.