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)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.7 (251)
Checking for powers of twoWebmaster C or C++ANSI5.7 (334)
Conversions between number systemsAli Nawkhas Murad C++ANSI5.7 (142)
GotoXYStack Overflow C*nix5.7 (449)
A simple example of hashtableAli Nawkhas Murad C++ANSI5.7 (155)
Example of polymorphismAli Nawkhas Murad C++ANSI5.6 (215)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.6 (104)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (375)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple5.6 (71)
Template Calculatorprog-bman C++ANSI5.6 (369)
Permutation GeneratorTreenef C++ANSI5.6 (487)
useful macros, functions and tricksyzb3 CANSI5.5 (117)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.5 (204)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.5 (231)
This C code uses the merge sort algorithm to sortAbhishek H.Dwivedi C or C++ANSI5.5 (671)
Simple Windows Socket Server ExampleJahan Addison C++Windows5.5 (155)
View the contents of a directoryfinnepower C++Windows5.5 (209)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (458)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.5 (14)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.5 (482)
One line swap of integersabhilash C or C++ANSI5.5 (210)
xor (en/de)cryption using a key fileyzb3 CANSI5.5 (117)
euler approximation methoderic mbakop C or C++ANSI5.4 (281)
Distanceprog-bman C++ANSI5.4 (189)
Simple linked list implementationyzb3 CANSI5.4 (139)
A game setup for DirectXPaul D C or C++ANSI5.4 (289)
Word wrap functionSean Hubbard CANSI5.4 (172)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.4 (171)
Three Dimension Coordinate Systems ConverterAli Nawkhas Murad C++ANSI5.4 (113)
A simple double linked list using OOP techniquesAli Nawkhas Murad C++ANSI5.4 (202)
Next 30
Previous 30