Posts

Switch Case Statement in C Programming with Example

Image
Switch Case Statement in C Programming with Example What is a Switch Statement? A switch statement tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier. The value provided by the user is compared with all the cases inside the switch block until the match is found. If a case match is found, then the default statement is executed, and the control goes out of the switch block. In this tutorial, you will learn- What is a Switch Statement? Syntax Flow Chart Diagram of Switch Case Example Nested Switch Why do we need a Switch case? Rules for switch statement: Syntax A general syntax of how switch-case is implemented in a 'C' program is as follows: switch( expression ) {        case value-1:                     Block-1;                     B

C Conditional Statement: IF, IF Else and Nested IF Else with Example

Image
C Conditional Statement: IF, IF Else and Nested IF Else with Example What is a Conditional Statement? In a 'C' program are executed sequentially. This happens when there is no condition around the statements. If you put some condition for a block of statements the flow of execution might change based on the result evaluated by the condition. This process is referred to as decision making in 'C.' The decision-making statements are also called as control statements. In 'C' programming conditional statements are possible with the help of the following two constructs: 1. If statement 2. If-else statement It is also called as branching as a program decides which statement to execute based on the result of the evaluated condition. In this tutorial, you will learn- What is a Conditional Statement? If statement Relational Operators The If-Else statement Conditional Expressions Nested If-else Statements Nested Else-if statements If sta