πŸŽ‰ New: Top 75 PHP Interview Questions for 2026 β€” Free for all learners

C Programming Cheat Sheet β€” Complete Syntax, Data Types, Functions, and Examples

P
php Guru
Β· November 24, 2025 Β· 4 min read Β· Updated November 24, 2025
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

πŸ“Œ Key Takeaways

  • C Programming Cheat Sheet β€” Complete Syntax, Data Types, Functions, and Examples
  • C Programming Language Cheat Sheet
  • C Language Basics
  • Data Types in C
  • C Variables and Constants
  • Operators in C
Advertisement

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 .

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.

P
php Guru
← Previous Post
UI UX Design Cheat Sheet
Next Post β†’
C++ Programming Cheat Sheet β€” Complete Syntax, OOP Concepts, and Examples for Beginners

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 5   +   4   =