C Basics Examples

Key takeaway: Practice C programming with 71+ runnable code examples covering I/O, loops, arrays, pointers, strings, recursion, and data structures — all with expected output to verify your understanding.

Begin with printing, swapping, sizes, character checks, and simple control flow. These concise programs build confidence with C syntax and the standard library.

Last updated: August 2026

Try Online C Compiler

C Program to Find the Frequency of Characters in a String

Program (C)
Example & Output

Counts frequency of a given char.

'l' occurs 3 times

C "Hello, World!" Program

Program (C)
Example & Output

Prints a greeting to the console.

Hello, World!

C Program to Print an Integer (Entered by the User)

Program (C)
Example & Output

Demonstrates integer I/O.

You entered: 123

C Program to Add Two Integers

Program (C)
Example & Output

Adds two integers and prints the sum.

Sum = 8

C Program to Multiply Two Floating-Point Numbers

Program (C)
Example & Output

Multiplies two floats.

Product = 10.00

C Program to Find ASCII Value of a Character

Program (C)
Example & Output

Prints ASCII of a character.

ASCII of A = 65

C Program to Compute Quotient and Remainder

Program (C)
Example & Output

Integer division and modulo.

Quotient = 6
Remainder = 2

C Program to Find the Size of int, float, double and char

Program (C)
Example & Output

Uses sizeof operator.

sizeof(char) = 1
sizeof(int) = 4
sizeof(float) = 4
sizeof(double) = 8

C Program to Demonstrate the Working of Keyword long

Program (C)
Example & Output

Shows long type usage.

long x = 1234567890

C Program to Swap Two Numbers

Program (C)
Example & Output

Swaps using temp variable.

a = 4, b = 3

C Program to Check Whether a Number is Even or Odd

Program (C)
Example & Output

Checks parity using modulo.

7 is odd

C Program to Check Whether a Character is a Vowel or Consonant

Program (C)
Example & Output

Checks vowel set.

e is vowel

C Program to Find the Largest Number Among Three Numbers

Program (C)
Example & Output

Finds max of three.

Largest = 17

C Program to Find the Roots of a Quadratic Equation

Program (C)
Example & Output

Quadratic formula for ax^2+bx+c.

Roots: 2.00, 1.00

C Program to Check Leap Year

Program (C)
Example & Output

Checks leap year rules.

2024 is leap year

C Program to Check Whether a Number is Positive or Negative

Program (C)
Example & Output

Checks sign.

-10 is negative

C Program to Check Whether a Character is an Alphabet or not

Program (C)
Example & Output

Uses isalpha.

# is not alphabet

C Program to Display Characters from A to Z Using Loop

Program (C)
Example & Output

Iterates ASCII letters.

ABCDEFGHIJKLMNOPQRSTUVWXYZ

C Program to Calculate Standard Deviation

Program (C)
Example & Output

Computes population std dev.

StdDev = 2.00

C Program Swap Numbers in Cyclic Order Using Call by Reference

Program (C)
Example & Output

Cyclic swap a->b->c.

a=3 b=1 c=2

C Program to Find Largest Number Using Dynamic Memory Allocation

Program (C)
Example & Output

Uses malloc for array.

Largest = 9

C Program to Count the Number of Vowels, Consonants and so on

Program (C)
Example & Output

Classifies characters.

Vowels=3 Consonants=7 Digits=3 Spaces=2 Others=1

C Program to Remove all Characters in a String Except Alphabets

Program (C)
Example & Output

Filters only letters.

HllWrld

C Program to Find the Length of a String

Program (C)
Example & Output

Uses strlen.

Length = 5

C Program to Concatenate Two Strings

Program (C)
Example & Output

Uses strcat safely.

Hello World

C Program to Copy String Without Using strcpy()

Program (C)
Example & Output

Manual copy loop.

Sample

C Program to Sort Elements in Lexicographical Order (Dictionary Order)

Program (C)
Example & Output

Sorts array of strings.

apple banana cherry

C Program to Store Information of a Student Using Structure

Program (C)
Example & Output

Defines struct and prints.

Alice 20 92.5

C Program to Add Two Distances (in inch-feet system) using Structures

Program (C)
Example & Output

Adds feet-inch distances.

9 feet 7 inch

C Program to Add Two Complex Numbers by Passing Structure to a Function

Program (C)
Example & Output

Adds complex numbers.

4.0 + 5.0i

C Program to Calculate Difference Between Two Time Periods

Program (C)
Example & Output

Subtracts times with borrow.

01:19:40

C Program to Store Data in Structures Dynamically

Program (C)
Example & Output

Allocates struct via malloc.

1 3.14

C Program to Write a Sentence to a File

Program (C)
Example & Output

Writes a line to file.

Written.

C Program to Read the First Line From a File

Program (C)
Example & Output

Reads first line of file.

First line: Hello file

C Program to Display its own Source Code as Output

Program (C)
Example & Output

Prints contents of source via argv[0].

(program source content)

C Program to Print Pyramids and Patterns

Program (C)
Example & Output

Simple star pyramid.

    *
   ***
  *****
 *******
*********

Frequently Asked Questions

Use gcc or clang. Run: gcc program.c -o program && ./program. On Windows use MinGW; on macOS/Linux, compilers are available via package managers. Or use our free online C compiler to run code directly in your browser.

C99 and above. The programs are compatible with C99 standard and newer. If you use older compilers, set -std=c99 flag or update your toolchain.

Yes, absolutely. These examples are intended for learning. Copy the code, experiment with changes (different inputs, edge cases), and observe the output to deepen understanding.

The examples use standard library functions and portable constructs, and have been tested on major platforms (Windows, macOS, Linux). They should compile and run with any standards-compliant C compiler.

Learn C the Practical Way

C remains one of the most influential programming languages. According to the TIOBE Index, C consistently ranks in the top 2 languages worldwide.

How to Use These Examples

  1. Browse topics in the sidebar and pick an example
  2. Read the description and study the code
  3. Copy the code and compile: gcc program.c -o program \&\& ./program
  4. Compare your output with the expected output shown
  5. Modify inputs or logic to experiment further

Topics Covered

  • Basic I/O, data types, and operators
  • Control flow: if/else, loops, switch
  • Functions, recursion, and modular design
  • Arrays, strings, and matrix operations
  • Pointers, dynamic memory, and file I/O
  • Structures, enums, and sorting algorithms

C Compiler Comparison

CompilerPlatformBest For
GCCLinux, macOS, Windows (MinGW)General use, standards compliance
ClangmacOS, Linux, WindowsFast compilation, clear errors
MSVCWindowsVisual Studio, Windows APIs
OnlineAny (browser)Quick testing, no install

Related:C Tutorial | Online C Compiler | C++ Examples

C Programming & Your Career — Everything You Need to Know

Can I Get a Job Learning C Programming?

Short answer: Yes. C programmers are in demand across embedded systems, operating systems, IoT, automotive software, game engines, and systems programming. Companies like Intel, Qualcomm, NVIDIA, Samsung, Texas Instruments, and ISRO actively hire C developers. According to the TIOBE Index 2024, C consistently ranks in the top 2 most-used programming languages globally.

Entry-level C programming roles typically pay ₹4–8 LPA in India and $60,000–$90,000 in the US. With 3–5 years of experience in embedded C or systems programming, salaries jump to ₹15–30 LPA (India) or $100,000–$150,000 (US). The demand is especially strong in hardware companies and semiconductor firms.

What Jobs Use C Programming Language?

Direct answer: C is used in roles where performance, hardware interaction, and memory control matter. Here are the key job categories:

  • Embedded Systems Engineer: Writing firmware for microcontrollers (STM32, Arduino, ESP32) — automotive, medical devices, IoT
  • Systems Programmer: Building OS kernels, device drivers, compilers — Linux kernel is 100% C
  • Game Engine Developer: Low-level engine code for performance-critical rendering (Unreal Engine uses C/C++)
  • Network/Security Engineer: Writing firewalls, packet analyzers, VPN software, cryptographic libraries
  • Aerospace/Defense: Flight control systems, satellite software, missile guidance — ISRO, DRDO, NASA all use C
  • Database Internals: MySQL, PostgreSQL, Redis, SQLite — all written in C
  • Compiler/Toolchain Developer: GCC, LLVM, interpreters for other languages

Should I Learn C or Python for My First Programming Language?

It depends on your career goal. If you want to understand how computers actually work — memory, pointers, CPU architecture — start with C. If you want to build applications quickly (web, data science, automation) — start with Python. Here's the honest comparison:

CriteriaCPython
Learning difficultyHard (manual memory, pointers)Easy (readable, forgiving)
Time to first program1–2 weeks1–2 days
Job marketEmbedded, systems, hardwareWeb, AI/ML, data science
Understanding of CS fundamentalsDeep (memory, OS, hardware)Surface-level
Switching to other languages laterEasy (C → anything)Moderate (Python → C is hard)
Best forCS students, hardware rolesBeginners, data/web roles

Our recommendation: If you're a CS/ECE student — learn C first, then Python. If you're a self-taught developer wanting web jobs — learn Python/JavaScript first, then C later if needed.

Should I Learn C Before Python or After?

Before, if possible. Learning C first gives you a deep understanding of how variables are stored in memory, how functions use the call stack, and why certain operations are expensive. When you then switch to Python, you'll understand what Python hides from you (garbage collection, dynamic typing, reference counting) — making you a significantly better programmer.

However, if C's difficulty discourages you from programming entirely, start with Python to build confidence, then come back to C within 6 months. The worst outcome is giving up programming because C felt too frustrating.

The Four Types of C Programming Explained

Direct answer: C programming is used in four major domains, each with different skills and tools:

  1. Systems Programming: Writing operating systems, kernels, device drivers. Tools: GCC, GDB, Makefiles. Example: Linux kernel development.
  2. Embedded Programming: Writing firmware for microcontrollers and hardware. Tools: Keil, IAR, PlatformIO. Example: STM32 sensor boards, Arduino projects.
  3. Application Programming: Building desktop software, databases, and utilities. Tools: Standard C libraries, POSIX APIs. Example: Redis, Git (written in C).
  4. Competitive/Algorithmic Programming: Solving DSA problems in C for speed and low memory. Tools: Online judges (Codeforces, LeetCode). Example: ICPC, Google Code Jam.

Do I Need Years of Experience for C Programming Jobs?

Not necessarily. Entry-level embedded C roles and fresh-graduate systems programming positions exist at companies like TCS, Infosys, Wipro, Continental, Bosch, and semiconductor startups. What matters more than years is demonstrable skill:

  • A GitHub portfolio with C projects (even simple ones like a custom shell, memory allocator, or linked list library)
  • Understanding of pointers, memory management, and data structures implemented from scratch
  • Familiarity with hardware concepts (registers, interrupts, GPIO) for embedded roles
  • Competitive programming ratings on platforms like Codeforces or HackerRank

Why Should I Learn C Programming?

Five reasons C is worth learning in 2026:

  1. Foundation for everything: Python, Java, Go, Rust — all built on concepts from C. Understanding C makes every other language easier.
  2. Performance: C is 10–100× faster than Python for compute-intensive tasks. When speed matters (real-time systems, games, HFT), C is the answer.
  3. Hardware access: C is the only widely-used language that lets you directly manipulate memory addresses, registers, and hardware.
  4. Longevity: C has been relevant for 50+ years and will remain so because operating systems, databases, and embedded devices aren't going away.
  5. Interview advantage: Companies like Google, Amazon, and Apple ask pointer/memory questions in interviews — C knowledge gives you an edge even for non-C roles.

What Certifications Help With C Programming Jobs?

Relevant certifications:

  • CLA (C Programming Language Certified Associate) by C++ Institute — internationally recognized, validates C fundamentals
  • CLP (C Certified Professional Programmer) — advanced certification for experienced C developers
  • Embedded C certifications by Udemy/Coursera — less formal but good for resume (e.g., "Mastering Microcontroller with Embedded C")
  • NPTEL C Programming certificate — free from IITs, recognized by Indian companies
  • Linux Foundation certifications — LFCS (Linux Foundation Certified SysAdmin) involves C/systems knowledge

That said, certifications are secondary to projects and practical skills. A GitHub repo with a working TCP server written in C impresses interviewers more than any certificate.

C Programming vs Other Languages: Which Should You Learn?

LanguageBest ForSpeedLearning CurveJob Market
CSystems, embedded, hardwareFastestHardNiche but high-paying
C++Games, HFT, competitive progVery fastVery hardLarge (finance, gaming)
PythonAI/ML, web, scriptingSlowEasyLargest overall
RustSafe systems programmingFast (≈C)HardGrowing rapidly
GoBackend, DevOps, cloudFastEasyStrong (infra companies)
JavaEnterprise, AndroidModerateModerateVery large (enterprise)

Is Learning C Worth It in 2026?

Absolutely yes. Despite being 50+ years old, C remains irreplaceable for:

  • The entire Linux kernel (30+ million lines of C code, maintained by thousands of developers)
  • Every operating system (Windows kernel, macOS kernel, Android's HAL layer)
  • IoT devices — 75 billion connected devices by 2025 (per Statista), most running C firmware
  • Electric vehicles — Tesla, Rivian, and traditional automakers use C for safety-critical ECU software
  • New languages like Rust and Zig are designed to be "better C" — meaning C's problem domain is alive and expanding

C is not going anywhere. It's the assembly language of the 21st century — you don't write it for everything, but understanding it makes you a fundamentally better engineer.

Sources: TIOBE Index 2024, StackOverflow Developer Survey 2024, Statista IoT Report, LinkedIn Job Postings Data. Practice C with the examples above — each one runs directly in your browser via our online C compiler.