Catalog / C Programming Language Cheatsheet
C Programming Language Cheatsheet
A concise reference for the C programming language, covering syntax, data types, standard library functions, and memory management.
Basic Syntax and Data Types
Program Structure
A C program consists of preprocessor directives, type definitions, function declarations, and function definitions. The |
|
Comments can be single-line ( |
Data Types
|
Integer (e.g., |
|
Single-precision floating-point number (e.g., |
|
Double-precision floating-point number (e.g., |
|
Single character (e.g., |
|
Represents the absence of a type. Used for functions that do not return a value or for generic pointers. |
Variables
Variables must be declared before use. Syntax: Example:
|
Initialization can be done during declaration: |
Use |
Operators and Control Flow
Operators
Arithmetic |
|
Assignment |
|
Comparison |
|
Logical |
|
Bitwise |
|
Increment/Decrement |
|
Control Flow Statements
if-else Statement:
|
switch Statement:
|
for Loop:
|
while Loop:
|
do-while Loop:
|
break and continue: |
Functions and Pointers
Functions
Functions are blocks of code that perform a specific task. Syntax:
|
Example:
|
Function prototypes declare the function before its definition. Example:
|
Pointers
Declaration |
|
Address-of Operator |
|
Dereference Operator |
|
Example |
|
Arrays and Pointers
Arrays and pointers are closely related. The name of an array is a pointer to the first element of the array. Example:
|
Pointer Arithmetic:
|
Standard Library and Memory Management
Standard Library Functions (stdio.h)
|
Formatted output to the console. |
|
Formatted input from the console. |
|
Opens a file. |
|
Closes a file. |
|
Formatted output to a file. |
|
Formatted input from a file. |
Memory Management (stdlib.h)
Syntax:
|
Syntax:
|
Syntax:
|
Syntax:
|
Example:
|