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)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple8.1 (19)
An example of simple stack using linked lists.Ali Nawkhas Murad C++ANSI7.9 (66)
Useful string functionsyzb3 CANSI7.9 (83)
One line swap of integersabhilash C or C++ANSI7.9 (110)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI7.8 (50)
A simple double linked list using OOP techniquesAli Nawkhas Murad C++ANSI7.8 (91)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.7 (586)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI7.6 (388)
This is Trigonometry Table made AlhamdulillahAbdul Haseeb Mir CWindows7.6 (7)
Simple linked list implementationyzb3 CANSI7.6 (68)
string to bitstring, bitstring to stringEsa Karjalainen CANSI7.5 (19)
Permutation GeneratorTreenef C++ANSI7.4 (335)
Simple Windows Socket Server ExampleJahan Addison C++Windows7.4 (68)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI7.3 (26)
Calandar generator printing a full calendar for any yearJoe C++ANSI7.3 (45)
Find the minimum distance between two linesGiacomo C or C++ANSI7.2 (11)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI7.2 (20)
Example of polymorphismAli Nawkhas Murad C++ANSI7.1 (121)
View the format of IEEE 754 floating point numbersAli Nawkhas Murad C++ANSI6.9 (92)
View the contents of a directoryfinnepower C++Windows6.9 (160)
An example use of a function pointerJayesh C++ANSI6.9 (15)
Simple swapping heapsortyzb3 C or C++ANSI6.8 (100)
Generate a spiral matrix for n elementsRaza C or C++ANSI6.8 (25)
Pascal's TriangleAli Nawkhas Murad C++ANSI6.7 (110)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.7 (347)
Failproof xor (en/de)cryptionyzb3 CANSI6.7 (89)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI6.6 (95)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.6 (361)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI6.6 (36)
Templated queue classAli Nawkhas Murad C++ANSI6.5 (87)
Next 30

Add a snippet!