C and C++ Source Code Snippets

Welcome to Cprogramming.com's programming code snippet repository. Peruse the archives or add your own snippets for others to use! (Check the following link a better definition of a snippet)

Sort by clicking on any of the headers.

SnippetAuthorLanguagePlatformRating (votes)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.2 (664)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.9 (440)
Permutation GeneratorTreenef C++ANSI6.6 (384)
a simple clockrichmond caesar CANSI6.2 (462)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI6.2 (79)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI6.2 (10)
xor (en/de)cryption using a key fileyzb3 CANSI6.2 (74)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI6.1 (172)
A code template for OpenGL / GLUTPerspective C or C++ANSI6.1 (230)
useful macros, functions and tricksyzb3 CANSI6.1 (71)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI6.1 (72)
View the contents of a directoryfinnepower C++Windows6.1 (184)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.1 (203)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI6.1 (77)
Template Calculatorprog-bman C++ANSI6.1 (276)
Example of polymorphismAli Nawkhas Murad C++ANSI6.1 (148)
Print variables with file and line number for debuggingmike lear C++ANSI6.1 (12)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI6.1 (76)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI6.1 (595)
An example of simple stack using linked lists.Ali Nawkhas Murad C++ANSI6.1 (90)
Checking for powers of twoWebmaster C or C++ANSI6.0 (295)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.0 (396)
GotoXYStack Overflow C*nix6.0 (364)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.0 (409)
Three ways to do a swapDavid Nielsen C or C++ANSI5.9 (345)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.9 (14)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.9 (138)
this one is better because a potential overflow (of the + operation) is avoided 5.9 (10)
Create a new file under linuxChol Nhial 5.9 (10)
Tic-TacToeptrs 5.9 (10)
Next 30

Add a snippet!