Switch is the case control statement that allows us to make a decision from the number of choices. It is also called switch case default. These three keywords go together to make up the control statement. Syntax of switch case default The integer expression following the switch keyword is any c expression that yields the integer value. [Characters also since they do have ASCII value interpretations] It could be an integer constant like 1, 2 or 3 or any expression that evaluates to an integer. The keyword case followed by an integer constant or character constant. Each constant in each case must be different from all other cases. The integer expression following the keyword switch is evaluated and yields an integer value. The integer value must be matched across the cases. When a match is found-The program executes following 1. The statement following that case. 2. All subsequent cases. 3. Default case as well. Keyword break stops executin...
Loops If something is worth doing, it's worth doing more than once. The versatility of computer lies in its ability to perform a set of instructions repeatedly. This involves repeating some portion of the program either a specific number of times or until a condition is being satisfied. This is done by loop control instructions. There are three methods by which we can repeat some portion of the program. while do while for Syntax of while loop initialize loop counter; while (test condition) { execute statement; increment counter; } @program- Flow chart Loop Counter / Index variable - Count variable sometimes called index variable or loop counter. in above program, variable count is loop counter or index variable. It is not necessary that the loop counter should always be an integer value. It can be real number as well. Instead of increment the loop counter we can decrement it as well. Other conditions which can be tested in while loops are: while (i<=10) while (i>=10 &...
Function - Function is a self-contained block of statements that performs a coherent task of some kind. @program Main () is the calling function and raj (), mahesh () are the called functions. Summary: - C program is a collection of one or more functions. Any C program contains at least one function. If there is only one function available in C program, it should be main (). If there are more than one functions available in C program, then one (one and only one) function should be main (), as programs begins with main (). There is no limit on the number of functions available in C program. Each function in a program is called, in the sequence specified by the function calls in the main (). When the called function has done its things, control returns to the main function. When main function runs out of the functions call, the program ends. A function gets called when a function name is followed by a semicolon. A function is defined when a function name is followed by pair of brac...
Comments
Post a Comment