Saturday, 30 November 2013
Introduction ==decision making and
branching
vC language possesses such decision
and branching by supporting likes that statement…
1. If statement.
2. Switch statement.
3. Conditional operator statement.
4. Go to statement.
Dangling else problem:
One
of the classic problem encountered when we start using nested if …else
statement is the dangling. This happen when a matching else is not available
for an if.
This
answer to this problem is very simple. Always match an else to the most
recent unmatched if in the current block. In some case it is possible that
the false condition is not required. In such solution else statement may be
omitted
“Else
is always paired with the most recent unpaired if”.
|
vRules for indentation.
When using
control statement often controls may be many other statements that must
follow it.
Ø Indent statements that are dependent on the
previous statement; provide at least three space of indentation.
Ø Align vertically else cause with their matching if
clause.
Ø Indent the statement is the block by at least
three spaces to the right of the brace.
Ø Align the opening and closing brace.
Ø Use appropriate comments to signify the beginning
and the end of blocks.
Ø Indent the nested statement as per above value.
Ø Code only one clause or statement on each line.
|
vRules for switch statement
· The switch expression must be an
integer type.
· Case labels must be in constant
or constant expression.
· Case labels must in unique. No
two labels can have the same values.
· Case labels must be end with a
semicolon.
· The break statement transfers the control
out of the switch statement.
· The break statement is optional. That is two
or more case labels may belong to the same statement.
· The default labels are optional.
If present it will executed when the expression does not find matching the
case.
· There can be at most one default labels.
· It is permitted to nest switch
statement.
|
Over all just remember.
Ø Be aware of dangling else
statement.
Ø
Friday, 29 November 2013
Monday, 25 November 2013
CONSTANTS VARIABLE AND DATA TYPES
Ø Do not use the
underscore as the first character of identifier because many of the identifiers
in the system library start with the underscore.
Ø Use only 31 or less than characters for
identifiers. This helps ensure portability of programs.
Ø Use meaningful
and intelligent variables name.
Ø Do not create
variable names that differ only by one or two letters.
Ø Each variable
used just before they used.
Ø Integer
constants, by default, assume int types.
Ø Don’t use the
lowercase 1 for long as it is usually confused with the number 1.
Ø Use single quote
for character constants and double quote for string constants.
Ø A character is
stored as an integer. It is therefore possible to perform arithmetic operation
on character.
Ø Don’t combine
declarations with executable statement.
Ø Don’t uses the
semicolon at the end of #defines directive.
Ø The character # should
be at the first column.
Ø C doesn’t
provide any warning or indication of over flow.
A variable define
inside a function is local to that function and not available to other function
Subscribe to:
Posts (Atom)