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)
A code template for OpenGL / GLUTPerspective C or C++ANSI6.9 (835)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.2 (328)
Checking for powers of twoWebmaster C or C++ANSI5.8 (381)
Distanceprog-bman C++ANSI5.6 (239)
Template Calculatorprog-bman C++ANSI6.0 (479)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.2 (620)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.9 (599)
A game setup for DirectXPaul D C or C++ANSI6.1 (405)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (415)
Count number of bits in a numberNaren Bala C or C++ANSI5.9 (60)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI4.5 (77)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.7 (145)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.3 (50)
Convert an integer into binary representationElabed Soufiane CANSI5.0 (91)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI6.7 (509)
Another merge sort of integer listManoj CANSI5.6 (90)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI4.6 (79)
Integer subset generatortreenef C++ANSI6.1 (50)
Find the minimum distance between two linesGiacomo C or C++ANSI4.3 (78)
One line swap of integersabhilash C or C++ANSI5.6 (249)
An example use of a function pointerJayesh C++ANSI5.7 (107)
Calculates 1 variable statisticsPaul Kennedy C++ANSI4.9 (84)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (933)
Creating, printing and free linked listsSyed Rafey Husain CANSI4.8 (78)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI6.3 (301)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.3 (94)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI4.2 (72)
A portable card deck class with shufflingSlyMaelstrom C++ANSI7.1 (527)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (98)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.3 (2547)
Next 30
Previous 30