C, C++, MFC  

C Programming Concepts and examples

🔹 Introduction

C is a structured, procedural, and powerful language that lays the foundation for modern programming. To master C, one must understand its core concepts:

  • 📦 Variables

  • 🔄 Loops

  • 📚 Arrays

  • 🛠️ Functions

  • 🎯 Pointers

👉 As the idiom goes: “Practice makes perfect.” The more you practice these concepts, the stronger your programming skills will be.

📦 1. Variables in C

A variable is a container that stores data values in memory.

🔹 Syntax

data_type variable_name = value;

🔹 Example

#include <stdio.h>
int main() {

    int age = 20; // Integer variable
    float marks = 88.5; // Floating-point variable
    char grade = 'A'; // Character variable    

    printf("Age: %d\n", age);
    printf("Marks: %.2f\n", marks);
    printf("Grade: %c\n", grade);

    return 0;
}

👉 Output

Age: 20

Marks: 88.50

Grade: A

🔄 2. Loops in C

Loops allow repetition of code until a condition is met.

🔹 Types of Loops

  1. for loop

  2. while loop

  3. do-while loop

Example (Print numbers 1 to 5) 

#include <stdio.h>

int main() {
    int i;
    // For Loop

    printf("Using for loop:\n");
    for(i=1; i<=5; i++) {
        printf("%d ", i);
    }
    // While Loop

    printf("\nUsing while loop:\n");

    i = 1;
    while(i <= 5) {
        printf("%d ", i);
        i++;
    }

    // Do-While Loop

    printf("\nUsing do-while loop:\n");
    i = 1;
    do {

        printf("%d ", i);
        i++;

    } while(i <= 5);
    return 0;
}

👉 Output

Using for loop:

1 2 3 4 5

Using while loop:

1 2 3 4 5

Using do-while loop:

1 2 3 4 5 

📚 3. Arrays in C 

An array is a collection of elements of the same data type stored at contiguous memory locations.

🔹 Example (Store and display 5 numbers)

#include <stdio.h>

int main() {

    int arr[5] = {10, 20, 30, 40, 50};
    int i;

    printf("Array elements:\n");

    for(i=0; i<5; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

👉 Output

Array elements:

10 20 30 40 50 

🛠️ 4. Functions in C 

A function is a block of code that performs a specific task.

🔹 Syntax

return_type function_name(parameters) {
   // code
}

🔹 Example (Function to add two numbers)

#include <stdio.h>

// Function declaration

int add(int a, int b);
int main() {

    int x = 5, y = 7, sum;
    sum = add(x, y); // Function call

    printf("Sum = %d", sum);
    return 0;
}

// Function definition

int add(int a, int b) {
    return a + b;
}

👉 Output

Sum = 12

🎯 5. Pointers in C 

A pointer is a variable that stores the memory address of another variable.

🔹 Example

#include <stdio.h>

int main() {
    int num = 10;
    int *ptr; // Pointer declaration
    ptr = &num; // Storing address of num

    printf("Value of num = %d\n", num);
    printf("Address of num = %p\n", &num);
    printf("Pointer pointing to = %d\n", *ptr);

    return 0;
}

👉 Sample Output 

Value of num = 10

Address of num = 0x7ffee0b3c8

Pointer pointing to = 10

🌟 Conclusion

C Programming is not just theory — it is logic + practice.

  • 📦 Variables help in storing data.

  • 🔄 Loops allow repetition.

  • 📚 Arrays manage collections of data.

  • 🛠️ Functions provide reusability.

  • 🎯 Pointers give memory control.

👉 As the idiom says: “Knowledge without practice is like a lamp without oil.” To master C, practice these concepts daily.

✨ Once you master these basics, you can move on to structures, file handling, and dynamic memory allocation in C.