C Programming Basics: Variables, Loops And function | Updated 2025

Basic C Programming Examples for Beginners

CyberSecurity Framework and Implementation article ACTE

About author

Meena (C Developer )

Meena is a skilled C developer specializing in low-level programming, embedded systems, and performance optimization. With extensive experience in writing efficient, portable, and maintainable C code, she focuses on system-level software, device drivers, and real-time applications. Passionate about sharing knowledge,

Last updated on 09th Sep 2025| 10386

(5.0) | 32961 Ratings

Introduction to C Language

The C programming language is one of the most influential and widely used programming languages in the history of computer science. Developed in the early 1970s by Dennis Ritchie at Bell Labs, C was originally designed to develop the UNIX operating system. Since then, it has become a foundational language for system programming, embedded systems, and application development. C Language is a procedural, structured programming language that provides low-level access to memory through the use of pointers while still offering high-level programming features. Its simplicity, efficiency, and portability make it ideal for writing operating systems, compilers, and other performance-critical applications. One of the key strengths of C is its ability to work closely with hardware. It allows direct manipulation of bits, bytes, and addresses, which is essential for systems-level programming. Despite being a powerful low-level language, C includes features like functions, loops, conditionals, and data structures, making it suitable for writing complex programs. C has influenced many modern languages such as C++, Java, C#, and Python, and understanding C provides a strong foundation for learning them. Its standardized syntax and extensive use in academia make it a common choice for teaching programming fundamentals. Programs written in C are compiled, which means they are translated into machine code before execution, resulting in fast and efficient performance. The language’s portability allows code to run on various platforms with minimal changes, as long as a compatible compiler is available. In summary, C is a powerful, efficient, and versatile programming language that continues to play a crucial role in software development. Whether you’re working on embedded systems, operating systems, or learning programming basics, mastering C is a valuable skill for any software developer.



To Earn Your Web Developer Certification, Gain Insights From Leading Data Science Experts And Advance Your Career With ACTE’s Web Developer Courses Today!


Hello World Program

The “Hello, World!” program is the simplest way to get started with C and test your development environment.

Example:

  • #include
  • int main() {
  • printf(“Hello, World!\n”);
  • return 0;
  • }

Explanation:

  • #include : Includes the standard input/output library.
  • main(): The entry point of every C program.
  • printf(): Prints text to the console.
  • return 0: Ends the program.

Output:

Hello, World!


    Subscribe To Contact Course Advisor

    Variables and Data Types

    • Definition: A variable is a named memory location used to store data that can be modified during program execution.
    • Declaration: Must be declared before use with a specific data type.
    • Example: int age;

    • Naming Rules: Must begin with a letter or underscore (_). Can contain letters, digits, and underscores. Cannot use keywords or special characters.
    • Initialization: Variables can be assigned a value at the time of declaration.
    • Example: int age = 25;

    • Scope: Determines the part of the program where the variable can be accessed (local, global, etc.)
    • Lifetime: The duration during which a variable exists in memory.
    • Data Types Article

      Data Types in C

      Basic (Primitive) Data Types:

      • int – Integer numbers (e.g., 1, -10)
      • float – Single-precision decimal numbers (e.g., 3.14)
      • double – Double-precision decimal numbers
      • char – Single character (e.g., ‘A’)
      • Derived Data Types:

        • Arrays
        • Pointers
        • Structures
        • Unions
        • Enumeration (enum): Used to define a set of named integer constants
        • Void Type: Represents “no value”; used for functions that return nothing
        • Type Modifiers: short, long, signed, unsigned – used to change the size or sign of data types


        • Would You Like to Know More About Web Developer? Sign Up For Our Web Developer Courses Now!


          If-else and Switch Cases

          Conditional statements control the flow based on conditions.

          If-else Example:

          • #include
          • int main() {
          • int marks = 70;
          • if (marks >= 90)
          • printf(“Grade: A\n”);
          • else if (marks >= 75)
          • printf(“Grade: B\n”);
          • else
          • printf(“Grade: C\n”);
          • return 0;
          • }

          Switch Case Example:

          • #include
          • int main() {
          • int choice = 2;
          • switch (choice) {
          • case 1: printf(“Start\n”); break;
          • case 2: printf(“Stop\n”); break;
          • default: printf(“Invalid\n”);
          • }
          • return 0;
          • }

          Course Curriculum

          Develop Your Skills with Web Developer Certification Course

          Weekday / Weekend BatchesSee Batch Details

          Loops: for, while, do-while

          Loops repeat blocks of code.

          For Loop:

          • for (int i = 1; i <= 5; i++) {
          • printf(“%d “, i);
          • }

          While Loop:

          • int i = 1;
          • while (i <= 5) {
          • printf(“%d “, i);
          • i++;
          • }
          Loops: for, while, do-while Article

          Do-While Loop:

          • int i = 1;
          • do {
          • printf(“%d “, i);
          • i++;
          • } while (i <= 5);

          Output for all:

          1 2 3 4 5

          Are You Interested in Learning More About Web Developer? Sign Up For Our Web Developer Courses Today!


          Arrays and Strings

          Arrays store multiple values of the same type.

          Array Example:

          • #int nums[5] = {1, 2, 3, 4, 5};
          • for (int i = 0; i < 5; i++) {
          • printf(“%d “, nums[i]);
          • }

          String Example:

          • char name[] = “Alice”;
          • printf(“Hello, %s\n”, name);

          Strings are arrays of characters terminated with \0.


          Web Development Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

          Functions and Recursion

          Functions and Recursion modularize code for reusability and clarity.

          Function Example:

          • int add(int a, int b) {
          • return a + b;
          • }
          • int main() {
          • printf(“Sum: %d\n”, add(3, 4));
          • return 0;
          • }

          Recursion Example:

          • int factorial(int n) {
          • if (n == 0) return 1;
          • return n * factorial(n – 1);
          • }
          • int main() {
          • printf(“Factorial: %d\n”, factorial(5));
          • return 0;
          • }

          Conclusion

          The Flood Fill algorithm is a powerful tool in computer graphics, from simple shape coloring to complex region analysis. While the recursive approach is easy to implement, the iterative method is preferred for robustness and performance. Understanding the principles of neighborhood traversal, color replacement, and boundary handling equips you to use this algorithm in a wide range of applications from gaming to image analysis. Whether you’re building a paint application or a grid-based puzzle solver,Pseudocode mastering flood fill gives you a strong foundation in both graphics and algorithmic logic.

    Upcoming Batches

    Name Date Details
    Web Developer Certification Course

    08 - Sep- 2025

    (Weekdays) Weekdays Regular

    View Details
    Web Developer Certification Course

    10 - Sep - 2025

    (Weekdays) Weekdays Regular

    View Details
    Web Developer Certification Course

    13 - Sep - 2025

    (Weekends) Weekend Regular

    View Details
    Web Developer Certification Course

    14 - Sep - 2025

    (Weekends) Weekend Fasttrack

    View Details