Friday, July 10, 2009

Conditionals In C Programming language

Conditionals

Conditionals are used within the if and while constructs:
    if (conditional_1)
{
...block of statements executed if conditional_1 is true...
}
else if (conditional_2)
{
...block of statements executed if conditional_2 is true...
}
else
{
...block of statements executed otherwise...
}
and any variant that derives from it, either by omitting branches or by including nested conditionals.

Conditionals are logical operations involving comparison of quantities (of the same type) using the conditional operators:

 < to  ="=">=  greater than or equal to
> greater than
and the boolean operators
 &&   and
|| or
! not

Another conditional use is in the switch construct:

    switch (expression)
{
case const_expression_1:
{
...block of statements...
break;
}
case const_expression_2:
{
...block of statements...
break;
}
default:
{
...block of statements..
}
}
The appropriate block of statements is executed according to the value of the expression, compared with the constant expressions in the case statement. The break statements insure that the statements in the cases following the chosen one will not be executed. If you would want to execute these statements, then you would leave out the break statements. This construct is particularly useful in handling input variables.



1. A First Program

2. Let's Compute

3. Loops

4. Symbolic Constants

5. Conditionals

6. Pointers

7. Arrays

8. Character Arrays

9. I/O Capabilities

10. Functions

11. Command-line Arguments

12. Graphical Interfaces: Dialog Boxes

No comments:

Blog List