c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf
c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf

C Programming Cheat Sheet — Complete Syntax, Data Types, Functions, and Examples

C Programming Language Cheat Sheet — Complete Guide for Beginners and Professionals

The C programming language is one of the most powerful, efficient, and widely used programming languages in the world. It forms the foundation for modern languages like C++, Java, and Python.

This C Cheat Sheet provides a quick reference for all important syntax, commands, and structures in C language programming — from variables to pointers, with practical examples.


C Language Basics

ConceptDescriptionExample
File Extension.cmain.c
CompilerUsed to compile code (e.g., GCC, Turbo C)gcc main.c -o main
ExecutionRun the compiled program./main
CommentAdds code explanations// single line or /* multi-line */

Example:

#include <stdio.h>
int main() {
    printf("Hello, World!");
    return 0;
}

Data Types in C

TypeKeywordSize (bytes)Range (approx.)
Integerint2 or 4-32,768 to 32,767
Characterchar1-128 to 127
Floatfloat43.4E-38 to 3.4E+38
Doubledouble81.7E-308 to 1.7E+308
Voidvoid0N/A

Example:

int age = 25;
float height = 5.9;
char grade = 'A';

C Variables and Constants

TypeSyntax ExampleExplanation
Variableint num = 10;Stores integer value
Constantconst float PI = 3.14;Value cannot be changed
Global VariableDeclared outside all functionsAccessible throughout program

Operators in C

TypeOperatorsExample
Arithmetic+ - * / %a + b
Relational== != > < >= <=if (a > b)
Logical`&&
Assignment= += -= *= /=x += 10
Increment/Decrement++ --i++
Bitwise`&^ ~ << >>`
Ternary? :result = (a > b) ? a : b;

Control Statements in C

StatementSyntaxDescription
ifif (condition) { }Executes if condition is true
if-elseif (condition) elseExecutes one of two blocks
switchswitch(expression)Executes based on multiple cases
breakbreak;Exits from a loop or switch
continuecontinue;Skips current iteration

Example:

if (age >= 18)
    printf("Eligible to vote");
else
    printf("Not eligible");

c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf
c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf

Loops in C

Loop TypeSyntaxUsage
for loopfor(init; condition; inc)Repeats known number of times
while loopwhile(condition)Repeats while condition is true
do-while loopdo { } while(condition);Executes at least once

Example:

for(int i=1; i<=5; i++)
    printf("%d ", i);

Functions in C

TypeSyntax ExampleDescription
Built-inprintf(), scanf()Provided by C library
User-definedvoid greet() { }Created by programmer
Function with returnint sum(int a, int b)Returns value

Example:

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

Arrays in C

TypeSyntax ExampleUsage
One-dimensionalint arr[5];Store multiple values
Two-dimensionalint matrix[3][3];For tables or grids

Example:

int nums[3] = {10, 20, 30};
printf("%d", nums[1]);  // Output: 20

Pointers in C

Pointers store memory addresses of variables.

Syntax:

int num = 10;
int *ptr = &num;
printf("%d", *ptr); // Output: 10
SymbolMeaning
&Address-of operator
*Value-at-address operator

Strings in C

Strings are arrays of characters ending with a null character \0.

Example:

char name[20] = "C Language";
printf("Welcome to %s", name);
FunctionUsage
strlen(str)Find string length
strcpy(dest, src)Copy string
strcmp(s1, s2)Compare strings
strcat(s1, s2)Concatenate strings
c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf

File Handling in C

ModeMeaning
"r"Read mode
"w"Write mode
"a"Append mode
"r+"Read + Write
"w+"Write + Read

Example:

FILE *fp = fopen("data.txt", "w");
fprintf(fp, "Hello C!");
fclose(fp);


FAQ — C Programming Language

Q1: Why is C still important in 2025?
C is the foundation of most modern languages and operating systems, including Linux and embedded systems.

Q2: How do I run a C program online?
Use online compilers like phponline.in C Editor or GCC locally.

Q3: What is the difference between C and C++?
C++ extends C by adding object-oriented programming (classes, inheritance, polymorphism).

Q4: What are the best IDEs for C programming?
Code::Blocks, Visual Studio Code, and Eclipse CDT are great options.

Q5: How do I learn C quickly?
Practice small projects like calculators, pattern printing, and file I/O programs.

Related Article
Machine Learning Cheatsheet (Unsupervised & Reinforcement Learning)

Machine Learning (ML) is a crucial part of artificial intelligence, enabling systems to automatically learn from data.This Machine Learning Cheatsheet Read more

HTML Cheat Sheet — Reference Guide to HTML Tags, Attributes, and Examples

HTML cheat sheet, HTML tags reference, HTML attributes list, HTML examples for beginners, semantic HTML guide, HTML forms tutorial, HTML Read more

Python Cheat Sheet — Complete Syntax Reference and Programming Examples

This Python Cheat Sheet is your quick reference guide for writing efficient Python code. Whether you’re preparing for coding interviews, Read more

PHP Cheat Sheet — Complete Syntax Reference and Programming Examples for Beginners

PHP Cheat Sheet — Complete Syntax Reference & Examples This PHP Cheat Sheet serves as a quick, structured reference for Read more

JavaScript Cheat Sheet — Complete ES6 Syntax, Functions, and DOM Methods with Examples

JavaScript Cheat Sheet — Complete Syntax Reference & Examples JavaScript is the core scripting language of the web, enabling interactivity, Read more

CSS Cheat Sheet — Complete CSS3 Selectors, Properties, and Layout Examples

CSS Cheat Sheet — Complete CSS3 Syntax, Selectors & Layout Examples Cascading Style Sheets (CSS) is the language used to Read more

Java Cheat Sheet — Complete Java Syntax, Data Types, Loops, and OOP Concepts for Beginners

Java Cheat Sheet — Complete Java Syntax, Classes, and Examples Java is a powerful, object-oriented programming language widely used for Read more

HTML5 Cheat Sheet — Complete Tag Reference & Examples

HTML5 is the core markup language of the modern web, used to structure content such as text, images, forms, and Read more

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments