YouTip LogoYouTip

C Nested If

C Nested if Statements

C Nested if Statements

-- Learning is not just technology, but also a dream!

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 - ">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 - ">C Standard Library - <a href="#" title="C Standard Library - ">C Standard Library - <a href="#" title="C Standard Library -

C Operators

C Loops

Dive Deeper

Software

Programming Languages

Scripting Languages

Web Services

Web Design & Development

Programming

Development Tools

Scripting

Web Services

Computer Science

C Nested if Statements

C Decision Making C Decision Making

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

C Decision Making C Decision Making

AI is thinking...

C Operators

C Loops

iFlytek Starry Sky Coding Plan includes free model call quotas for DeepSeek, GLM, Kimi, MiniMax. A one-stop experience and deployment platform. Configuration Guide Β₯3.9/month Activate Now

Click me to share notes

Cancel

Write a note...

Image URL

Image Description

Image Size Γ—

Share Note

  • Nickname Nickname (Required)
  • Email Email (Required)
  • Reference URL Reference URL

Category Navigation

← Php IntdivPhp Error Handling β†’