Start your programming journey with one of the most powerful and foundational languages — C. This comprehensive course is designed for absolute beginners as well as intermediate learners who want to build a solid understanding of programming using the C language. Whether you're preparing for college-level programming, cracking technical interviews, or planning to explore systems or embedded development, this course covers everything step-by-step. Through hands-on examples, real-world practice problems, and structured explanations, you’ll learn how to write clean and efficient C code — from your first printf() to advanced data structures and memory management.
Conditional statements allow your C programs to make decisions during execution. They evaluate expressions and execute code blocks depending on whether the conditions are true or false. These are essential for flow control and implementing logic.
if statementif...else statementif...else if...else laddernested if statementsswitch statementif StatementExecutes a block of code if a specified condition is true.
int age = 20;
if (age >= 18) {
printf("You are eligible to vote.\n");
}
if...else StatementExecutes one block if the condition is true, another if it's false.
int num = 7;
if (num % 2 == 0) {
printf("Even number\n");
} else {
printf("Odd number\n");
}
if...else if...else LadderUsed when you need to check multiple conditions in a sequence.
int marks = 85;
if (marks >= 90) {
printf("Grade A\n");
} else if (marks >= 75) {
printf("Grade B\n");
} else if (marks >= 60) {
printf("Grade C\n");
} else {
printf("Grade D\n");
}
if StatementsAn if block inside another if block. Used for complex decision trees.
int age = 25;
int hasID = 1;
if (age >= 18) {
if (hasID == 1) {
printf("Entry allowed.\n");
} else {
printf("Please bring your ID.\n");
}
}
switch StatementUsed when you have multiple specific values to compare against a single variable.
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
default:
printf("Invalid day\n");
}
if-else vs switch| Criteria | if-else | switch |
|---|---|---|
| Conditions | Any logical expression | Only constant values |
| Use case | Range checks, complex logic | Multiple specific values |
| Performance | Slower for many cases | Faster with many cases |
int userChoice = 2;
switch (userChoice) {
case 1:
printf("Show SSC Preparation Materials\n");
break;
case 2:
printf("Show IT Fundamentals Course\n");
break;
default:
printf("Browse All Courses on UdaanPath\n");
}
if-else ladder.if.if, else, and switch help execute code blocks conditionally.switch is best for fixed constant checks; if is flexible for ranges and logic.
In the next chapter, we will explore Loops in C – understanding for, while, and do-while to perform repetitive tasks efficiently.