Skip to content

Simplified comprehensive notes on the C programming language.

Notifications You must be signed in to change notification settings

sajibsrs/notes-on-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notes on C Programming

Simplified comprehensive notes on the C programming language.

Contents

Table of Contents
  • Installation
  • Program Structure
  • Running a program
  • Data types
  • Function
  • Special
  • Headers
  • Storage Classes
  • Type Qualifiers
  • Type Specifiers
  • Scope
  • Storage Duration
  • Linkage
  • Operator Precedence
  • Bitwise Operators
  • Memory
  • Pointer & reference
  • Macro
  • Preprocessor directives
  • Error Handling
  • Date & time
  • Testing & Debugging
  • Threads
  • Portability
  • Data structures
  • Algorithms
  • Object Oriented Programming (OOP)
  • Standard library
  • Books & Resources (Recommendation)

Installation

Compiler

Preparing Code Editor / IDE

Program Structure

Include Directive

The main() function

Running a program

  • Source code
  • Compilation
  • Linking
  • Execution

Data types

  • Primitive
  • Compound / User defined

struct (Structure)

union

enum (Enumerator)

Variable

  • Declaration
  • Initialization
  • Casting

Input & output (IO)

Array

  • Fixed Length Array
  • One Dimensional Array
  • Multi-dimensional Array
  • Variable Length Array (VLA)
  • Dynamic Array

Character & string

Format Specifier

Conversion Specifier

Function

Definition

  • Return type
  • Name
  • Parameters
  • Variadic function

Special

  • Type Cast
  • Incomplete Type
  • Compound Literal
  • Designated Initialization

Headers

Storage Classes

Only one storage class may appear in a declaration. If present it should come first.

  • auto
  • static
  • extern
  • register (variable only)

Type Qualifiers

A declaration may contain zero or more type qualifiers.

  • const
  • volatile
  • restrict
  • inline (function only)

Type Specifiers

  • void
  • char
  • short
  • int
  • long
  • float
  • double
  • signed
  • unsigned

Scope

  • File
  • Block
  • Function prototype
  • Function
  • Nested

Storage Duration

  • Automatic
  • Static
  • Thread
  • Dynamic

Linkage

  • Internal
  • External

Operator Precedence

Bitwise Operators

Memory

Pointer & reference

Dynamic memory management

Others:

  • alloca()
  • aligned_alloc()
  • reallocarray()

Memory management issues

Macro

  • User Defined Macro
  • Preprocessor Directives
  • Built-in Macros
  • _Generic (c11)

Error Handling

Date & time

Testing & Debugging

Threads

Portability

Data structures

Algorithms

Recursion

Object Oriented Programming (OOP)

Tips & Tricks

Standard library

C89/C90 Standard Library Headers

These are the original headers introduced in ANSI C (C89/C90), which remain widely used.

Header Description
<assert.h> Provides the assert macro for debugging purposes.
<ctype.h> Functions for character classification and conversion, such as isalpha and toupper.
<errno.h> Defines macros for error handling, like errno.
<float.h> Defines limits of floating-point types, like FLT_MAX.
<limits.h> Defines limits for fundamental types, like INT_MAX.
<locale.h> Functions for setting and using locale information, such as setlocale.
<math.h> Mathematical functions, including sin, cos, sqrt, etc.
<setjmp.h> Provides setjmp and longjmp for non-local jumps (used in exception handling).
<signal.h> Signal handling functions, like signal and raise.
<stdarg.h> Support for variable argument functions using va_list, va_start, and va_end.
<stddef.h> Common definitions like NULL, size_t, and ptrdiff_t.
<stdio.h> Standard input/output functions, including printf, scanf, fopen, etc.
<stdlib.h> General utilities, including memory management (malloc), program control, and conversions.
<string.h> String manipulation functions like strlen, strcpy, strcat, etc.
<time.h> Date and time functions, including time, clock, and difftime.

C95 Standard Library Headers

C95 introduced some additional headers to support new data types and wide characters.

Header Description
<iso646.h> Defines alternative spellings for operators (e.g., and for &&).
<wchar.h> Functions for handling wide characters and strings, including wprintf, wcscpy.
<wctype.h> Functions for classifying wide characters, such as iswalpha.

C99 Standard Library Headers

The C99 standard introduced several headers for complex numbers, type-generic math, and fixed-width integer types.

Header Description
<complex.h> Complex number types and operations, like cabs and cimag.
<fenv.h> Functions to control floating-point environment (rounding, exceptions).
<inttypes.h> Format macros and extended integer types, such as int64_t.
<stdbool.h> Defines bool, true, and false for Boolean operations.
<stdint.h> Fixed-width integer types like int32_t, uint8_t.
<tgmath.h> Type-generic macros for math functions (e.g., sqrt can work on float, double, and long double).

C11 Standard Library Headers

The C11 standard introduced threads, atomics, and better support for Unicode.

Header Description
<stdalign.h> Defines macros for specifying alignment (e.g., alignas).
<stdatomic.h> Atomic operations for multi-threaded programming.
<stdnoreturn.h> Defines noreturn for functions that do not return (e.g., exit).
<threads.h> Thread support library, including thrd_t and functions for thread management.
<uchar.h> Support for Unicode characters, including types like char16_t and char32_t.

C23 Standard Library Headers

The C23 standard introduces improvements and some additional features to ease programming tasks. (Note: Some of these may still be tentative or implementation-specific in C23.)

Header Description
<stdckdint.h> Checked integer arithmetic functions to handle overflow in integer operations safely.
<stdfloat.h> Defines standardized floating-point types with specific precision, such as float32_t and float64_t.

Books & Resources (Recommendation)

Books

Title Edition Year Author(s) Audience C Version
C Programming: A Modern Approach 2nd 2009 K. N. King Everyone Up to C99
Modern C for Absolute Beginners 2nd 2024 Slobodan Dmitrović Beginner Up to C23
Intermediate C Programming 2nd 2024 Yung-Hsiang Lu, George K. Thiruvathukal Everyone Up to C23
Tiny C Projects 1st 2022 Dan Gookin Intermediate Up to C23

Classics

Books listed here are classics. They are considered the best so far, but some of the topics and methods might not be relevant, deprecated or removed. They are mostly published 30-50 years ago (some more or less). Fortunately C language itself haven't changed that much.

Title Edition Year Author(s) Audience C Version
The C Programming Language 1st, 2nd 1978, 1988 Brian W. Kernighan, Dennis M. Ritchie Everyone Up to C89
C Programming: A Modern Approach 1st 1996 K. N. King Everyone Up to C89
Expert C Programming: Deep C Secrets 1st 1994 Peter van der Linden Expert Up to C89

About

Simplified comprehensive notes on the C programming language.

Resources

Stars

Watchers

Forks