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)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI4.9 (104)
Print variables with file and line number for debuggingmike lear C++ANSI2.6 (37)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.2 (2064)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (36)
View the format of IEEE 754 floating point numbersAli Nawkhas Murad C++ANSI6.5 (470)
Macro to swap nibble of BYTET Sailesh C or C++ANSI4.0 (49)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI5.8 (186)
xor (en/de)cryption using a key fileyzb3 CANSI5.5 (117)
This C code recursively sorts an array of upto 20Abhishek H.Dwivedi C or C++ANSI5.3 (237)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (671)
A game setup for DirectXPaul D C or C++ANSI5.4 (287)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.5 (481)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (455)
Distanceprog-bman C++ANSI5.4 (189)
Checking for powers of twoWebmaster C or C++ANSI5.7 (333)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.5 (230)
Word wrap functionSean Hubbard CANSI5.2 (162)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.5 (202)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.7 (251)
Permutation GeneratorTreenef C++ANSI5.6 (487)
Creating, printing and free linked listsSyed Rafey Husain CANSI2.9 (36)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (871)
Calculates 1 variable statisticsPaul Kennedy C++ANSI2.5 (35)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI2.4 (36)
Count number of bits in a numberNaren Bala C or C++ANSI4.7 (10)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (374)
a simple clockrichmond caesar CANSI5.9 (786)
euler approximation methoderic mbakop C or C++ANSI5.4 (281)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.3 (168)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI5.8 (135)
Next 30
Previous 30

Add a snippet!