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)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI7.9 (40)
Shorter version of gotoxyNedeljko CLinux7.8 (25)
A simple double linked list using OOP techniquesAli Murad C++ANSI7.6 (58)
Function pointer to member function of classselvam C++ANSI7.6 (5)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.4 (175)
This C code assigns codes to a maximum of 10 charsAbhishek H.Dwivedi C or C++Windows7.4 (5)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI7.4 (10)
Permutation GeneratorTreenef C++ANSI7.4 (322)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI7.3 (10)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple7.2 (13)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI7.1 (16)
View the contents of a directoryfinnepower C++Windows6.9 (159)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.7 (340)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.6 (356)
This is Trigonometry Table made AlhamdulillahAbdul Haseeb Mir CWindows6.6 (5)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI6.5 (13)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.5 (19)
Simple Windows Socket Server ExampleJahan Addison C++Windows6.5 (26)
Checking for powers of twoWebmaster C or C++ANSI6.4 (266)
a simple clockrichmond caesar CANSI6.4 (416)
Color header for Windows that integrates with coutSang-drax C++Windows6.3 (206)
A game setup for DirectXPaul D C or C++ANSI6.3 (229)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI6.3 (564)
Three ways to do a swapDavid Nielsen C or C++ANSI6.3 (317)
Convert an integer into binary representationElabed Soufiane CANSI6.2 (14)
Print variables with file and line number for debuggingmike lear C++ANSI6.2 (10)
GotoXYStack Overflow C*nix6.2 (321)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI6.2 (168)
friend function exampleAli Murad C++ANSI6.2 (25)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI6.2 (19)
Next 30
Previous 30

Add a snippet!