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++ANSI5.4 (139)
Print variables with file and line number for debuggingmike lear C++ANSI4.1 (81)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.3 (2546)
Find the minimum distance between two linesGiacomo C or C++ANSI4.3 (78)
View the format of IEEE 754 floating point numbersAli Nawkhas Murad C++ANSI6.5 (516)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (98)
binary tree creation, traversal and searchSyed Rafey Husain C or C++ANSI6.3 (301)
xor (en/de)cryption using a key fileyzb3 CANSI5.4 (151)
This C code recursively sorts an array of upto 20Abhishek H.Dwivedi C or C++ANSI5.4 (273)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (710)
A game setup for DirectXPaul D C or C++ANSI6.1 (405)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.9 (599)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.2 (620)
Distanceprog-bman C++ANSI5.6 (239)
Checking for powers of twoWebmaster C or C++ANSI5.8 (381)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.2 (328)
Word wrap functionSean Hubbard CANSI5.6 (234)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.7 (249)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.8 (297)
Permutation GeneratorTreenef C++ANSI5.6 (527)
Creating, printing and free linked listsSyed Rafey Husain CANSI4.8 (78)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (933)
Calculates 1 variable statisticsPaul Kennedy C++ANSI4.9 (84)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI4.5 (77)
Count number of bits in a numberNaren Bala C or C++ANSI5.9 (60)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (415)
a simple clockrichmond caesar CANSI6.4 (1091)
euler approximation methoderic mbakop C or C++ANSI5.6 (329)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.4 (216)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI6.0 (190)
Next 30
Previous 30