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)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (671)
A code template for OpenGL / GLUTPerspective C or C++ANSI6.4 (636)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.5 (230)
Checking for powers of twoWebmaster C or C++ANSI5.7 (329)
Distanceprog-bman C++ANSI5.4 (189)
Template Calculatorprog-bman C++ANSI5.4 (340)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (454)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.5 (481)
A game setup for DirectXPaul D C or C++ANSI5.4 (287)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI2.4 (36)
Calculates 1 variable statisticsPaul Kennedy C++ANSI2.3 (34)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (868)
Print variables with file and line number for debuggingmike lear C++ANSI2.6 (37)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.4 (83)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.2 (13)
Convert an integer into binary representationElabed Soufiane CANSI3.3 (44)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI6.6 (449)
An example use of a function pointerJayesh C++ANSI3.6 (43)
Another merge sort of integer listManoj CANSI4.1 (47)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI2.9 (38)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (36)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.2 (1973)
One line swap of integersabhilash C or C++ANSI5.4 (202)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI2.3 (33)
Macro to swap nibble of BYTET Sailesh C or C++ANSI3.9 (47)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI5.7 (173)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI3.4 (44)
Integer subset generatortreenef C++ANSI4.9 (11)
Creating, printing and free linked listsSyed Rafey Husain CANSI2.9 (36)
A portable card deck class with shufflingSlyMaelstrom C++ANSI6.8 (395)
Next 30
Previous 30

Add a snippet!