Category: Instructions in C

The continue Statement in C Language 25

The continue statement in C Language

Let us understand the continue statement in C programming language. continue statement works similar to break statement in C. Instead of terminating the loop statement, it will force next iteration of the loop. continue statement can be used with for loop, while loop and do-while loop. Sometimes there arises a situation where we don’t want to execute the certain statements within the loop but we want to continue the execution of the loop till the condition is satisfied. This can be done using continue statement. Consider the below example, for(i=0;i<10;i++) { /*statement1*/ /*statement2*/ /*statement3*/ /*statement4*/ } Let us suppose, when the...

The goto Keyword in C Language 15

goto statement in C Language

goto statement in C programming language is used for unconditional jump from one part of the program to another part of the program. It is always suggested not to use goto statement as this reduces the readability of the program. Using goto statement in C programming language is considered as poor programming approach. The goto statement consists of two parts: label and goto keyword. Example: /*use of goto statement*/ #include<stdio.h.> #include<conio.h> void main(){ int a; goto label; a = 10; printf(“%d”, a); label: a = 20; printf(“%d”, a); } Output: 20 When goto label is encountered, control goes to the...

switch statement in C 40

switch statement in C

The switch statement in C is very powerful decision making statement. It reduces the complexity of the program. Hence increases the readability of the program. Switch statement accepts single input from the user and based on that input executes a particular block of statements. Syntax of switch statement in C: switch(expression){ case constant 1: perform this; case constant 2: perform this; case constant 3: perform this; case constant 4: perform this; . . . default: perform this; } Control passes to the statement whose case constant-expression matches the value of switch ( expression ). The switch statement can include any...

Conditional operator in C 49

Conditional operator in C

Conditional operator in C is also known as ternary operator. It is called ternary operator because it takes three arguments. It evaluates an expression returning a value if that expression is true and different one if the expression is evaluated as false. Syntax: condition ? result1 : result2; If the condition is true, result1 is returned else result2 is returned. Examples: 10==5 ? 11: 12; // returns 12, since 10 not equal to 5. 10!=5 ? 4 : 3; // returns 4, since 10 not equal to 5. 12>8 ? a : b; // returns the value of a, since...

if else in C programming 36

if else in C programming

Let us understand if-else statement in C programming language. Here, if and else are the keywords in C. Syntax of if else in C: if (condition is true){ /*1st block of statements*/ } else{ /*2nd block of statements*/ } The keyword if tells the compiler that what follows is decision control statement. The block of statements to be executed must be enclosed in opening and closing braces. If only one statement needs to be executed then braces need not be used. Let us understand if-else statement using an example. Example: int a = 10; if (a == 10) { printf(“You...

if statement in C 23

if statement in C

In the if statement, if is the keyword in C. Syntax: if (condition is true){ /*block of statements to be executed*/ } The keyword if tells the compiler that what follows is decision control statement. The block of statements to be executed must be enclosed in opening and closing braces. If only one statement needs to be executed then braces need not be used. Let us understand if statement using an example. Example of if statement in C: int a = 10; if (a == 10){ printf(“You are in if block\n”); printf(“The value of a is %d\n”, a); } printf(“You...