C Nested if Statements
-- Learning is not just technology, but also a dream!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
C Tutorial
C Language Tutorial C Introduction C Environment Setup C VScode C Program Structure C Basic Syntax C Data Types C Variables C Constants C Storage Classes C Operators C Decision Making C Loops C Functions C Scope Rules C Arrays C enum (Enumeration) C Pointers C Function Pointers & Callback Functions C Strings C Structures C Unions C Bit Fields C typedef C Input & Output C File I/O C Preprocessors C Header Files C Type Casting C Error Handling C Recursion C Variable Arguments C Memory Management C Undefined Behavior C Command Line Arguments C Safe Functions C Sorting Algorithms C Project Structure C Examples C Classic 100 Examples C Quiz
C Standard Library
C Standard Library - Reference Manual <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library -
Dive Deeper
Software
Programming Languages
Scripting Languages
Web Services
Web Design & Development
Programming
Development Tools
Scripting
Web Services
Computer Science
C Nested if Statements
In the C language, nested if-else statements are valid, which means you can use one if or else if statement inside another if or else if statement(s).
Syntax
The syntax for a nested if statement in C is as follows:
if( boolean_expression 1)
{
/* Executes when the boolean expression 1 is true */
if(boolean_expression 2)
{
/* Executes when the boolean expression 2 is true */
}
}
You can nest else if...else in the same way as you have nested if statements.
Example
Example
#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 100;
int b = 200;
/* check the boolean condition */
if( a == 100 )
{
/* if condition is true then check the following */
if( b == 200 )
{
/* if condition is true then print the following */
printf("Value of a is 100 and b is 200n" );
}
}
printf("Exact value of a is %dn", a );
printf("Exact value of b is %dn", b );
return 0;
}
When the above code is compiled and executed, it produces the following result:
Value of a is 100 and b is 200
Exact value of a is 100
Exact value of b is 200
AI is thinking...
Click me to share notes
Write a note...
Image URL
Image Description
Share Note
- Nickname Nickname (Required)
- Email Email (Required)
- Reference URL Reference URL
YouTip