The C programming language is a foundational, general-purpose computer programming language created by Dennis Ritchie at Bell Labs in 1972.

Originally developed to write the UNIX operating system, C is widely regarded as the “mother of all programming languages” because it bridges the gap between low-level machine execution and high-level programming abstractions.

Learn software development

1. Basic Structure

#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

2. Variables & Data Types

int age = 25;
float price = 19.99;
double pi = 3.14159;
char grade = 'A';
char name[] = "John";
TypeExampleTypical Size
int104 bytes
float3.144 bytes
double3.141598 bytes
char'A'1 byte

3. Input & Output

printf("Age: %d", age);

scanf("%d", &age);
scanf("%f", &price);
scanf("%c", &grade);

Common format specifiers:

%d  int
%f  float
%lf double
%c  char
%s  string

4. Operators

+   -   *   /   %       // Arithmetic
==  !=  >   <   >= <=   // Comparison
&&  ||  !               // Logical
++  --                  // Increment/Decrement

5. Conditions

if (age >= 18) {
    printf("Adult");
} else {
    printf("Minor");
}
switch (choice) {
    case 1:
        printf("One");
        break;
    default:
        printf("Other");
}

6. Loops

for (int i = 0; i < 5; i++) {
    printf("%d\n", i);
}
while (condition) {
    // code
}
do {
    // code
} while (condition);

7. Functions

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

int result = add(5, 3);

8. Arrays

int numbers[] = {10, 20, 30, 40};

printf("%d", numbers[0]);

9. Strings

char name[20] = "Codeflare";

printf("%s", name);

Useful header:

#include <string.h>

strlen(name);
strcpy(dest, src);
strcmp(str1, str2);

10. Pointers

int age = 25;
int *ptr = &age;

printf("%d", *ptr);
  • & → address of a variable
  • * → value stored at an address

11. Structures

struct Student {
    char name[50];
    int age;
};

struct Student student1 = {"John", 20};

12. Dynamic Memory

#include <stdlib.h>

int *ptr = malloc(5 * sizeof(int));

free(ptr);

13. Comments

// Single-line comment

/*
   Multi-line comment
*/

14. Compile & Run

gcc program.c -o program
./program

Remember: C programming language is strongly typed, case-sensitive, and uses ; to terminate most statements.

Share
Published by
codeflare

Recent Posts

Homebrew Tutorial

What Is Homebrew? Homebrew is a package manager for macOS and Linux that makes it easy to…

4 days ago

10 Ways to Loop Through a JavaScript Array

JavaScript gives you several ways to iterate over an array. Some are better for simple…

6 days ago

Build a Node JS Web Server

A web server is the software responsible for receiving requests from clients, processing those requests,…

1 week ago

Shell Prompt Tutorial

A shell prompt is the text displayed by a command-line shell to show that it is ready…

2 weeks ago

The SOC Analyst

A SOC Analyst (Security Operations Center Analyst) is one of the frontline defenders of an organization’s cybersecurity…

3 weeks ago

Building an Offline-Friendly Image Upload System

Most image upload systems assume one thing: the user has a stable internet connection. That assumption…

4 weeks ago