C Tutorials

C if else Statement –

In C programming, decision-making is a fundamental concept that allows a program to react differently in different circumstances. The if-else statement is used to implement the argument to decide. It enables the program to evaluate a situation and execute a block of the code, whether the problem is correct or wrong.

The if-else statement allows us to control the flow of execution. It helps the programmer to build dynamic and responsible applications that can handle real-world conditions user checking input, validating conditions, or reacting in various states in a program.

The if-else statement in C is used to perform the operations based on some specific condition. The operations specified in the if block are executed if and only if the given condition is true.

Types of if Statements in C++

There are several types of if statements in C language. Some of them are as follows:

  • If statement
  • If-else statement
  • If else-if ladder
  • Nested if

Each decision-making structure in C programming provides unique functionalities that boost programming flexibility because they perform distinct tasks.

1) if Statement

In C programming, the if statement is used to check some given condition and perform some operations depending upon the correctness of that condition. It is mostly used in scenarios where we need to perform different operations for various situations.

Syntax

It has the following syntax:

In this syntax,

  • The if statement represents a conditional control structure that is used to execute a block of code only if the specified condition (expression) evaluates to true.
  • The expression inside the parentheses is evaluated:
  1. If it returns true (non-zero), the code inside the {} block execute.
  2. If it returns false (zero), the block is skipped.

Flowchart of if Statement

if statement in c

C if Statement Example

Let us take a simple example to illustrate the if statement in C.

Example

Compile and Run

Output

Enter a number:4
4 is an even number

Another Example to find the largest number of the three

Let us take an example to find to largest number of three numbers using the if statement in C.

Example

Compile and Run

Output

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button