C Rules and Targets 🎯

beginner
13 min

C Rules and Targets 🎯

Welcome to our deep dive into the world of C programming! In this lesson, we'll cover the essential rules and targets that every C programming beginner and intermediate should know. 📝

Understanding C 💡

C is a high-level, general-purpose programming language that emphasizes low-level memory access. It's used extensively in system software, device drivers, embedded systems, and game development.

Basic Syntax and Rules 📝

Variables and Data Types

  • Integer: int varName;
  • Float: float varName;
  • Character: char varName;
  • Boolean: In C, boolean values are represented using 0 (false) and non-zero values (true). int isTrue = 1;

Operators

  • Arithmetic: +, -, *, /, %
  • Assignment: =
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: &&, ||

Control Structures

  • If Statement:
    c
    if (condition) { // Code to be executed if condition is true }
  • If-Else Statement:
    c
    if (condition) { // Code to be executed if condition is true } else { // Code to be executed if condition is false }
  • Switch-Case Statement:
    c
    switch (expression) { case constant_expression1: // Code to be executed if expression matches constant_expression1 break; case constant_expression2: // Code to be executed if expression matches constant_expression2 break; // More cases... default: // Code to be executed if expression doesn't match any case }

Practical Examples 💡

Example 1: Simple Input and Output

c
#include <stdio.h> int main() { int number; printf("Enter a number: "); scanf("%d", &number); printf("You entered: %d\n", number); return 0; }

Example 2: Basic Decision Making

c
#include <stdio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); if (age >= 18) { printf("You are eligible to vote.\n"); } else { printf("You are not eligible to vote.\n"); } return 0; }

Quiz 💡

Quick Quiz
Question 1 of 1

Which of the following is a boolean data type in C?

By the end of this lesson, you should have a solid understanding of the basic syntax, data types, operators, and control structures in C programming. Happy coding! 🎉