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)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows9.0 (46)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.6 (238)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
Create a new file under linuxChol Nhial 5.3 (8)
Creating, printing and free linked listsSyed Rafey Husain CANSI6.4 (8)
Distanceprog-bman C++ANSI5.5 (184)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI6.2 (10)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI8.7 (48)
euler approximation methoderic mbakop C or C++ANSI5.9 (256)
Eventhandling macro for classesToolsDevler 5.3 (8)
Example of polymorphismAli Nawkhas Murad C++ANSI8.5 (94)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI8.5 (71)
Failproof xor (en/de)cryptionyzb3 CANSI8.7 (65)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI8.4 (54)
Find the minimum distance between two linesGiacomo C or C++ANSI7.2 (11)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple7.9 (17)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI7.2 (20)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI8.2 (33)
friend function exampleAli Nawkhas Murad C++ANSI6.5 (38)
Function pointer to member function of classselvam C++ANSI8.9 (15)
Generate a spiral matrix for n elementsRaza C or C++ANSI6.8 (25)
GetLastError error lookup toolKen Fitlike CWindows5.8 (185)
GotoXYStack Overflow C*nix6.3 (339)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.9 (14)
Implementing a directory listing on LinuxJoshith C*nix6.3 (12)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI8.4 (52)
Integer Partitions from 1 to NChristopher Brown 5.3 (8)
Integer subset generatortreenef C++ANSI5.3 (10)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI7.6 (387)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (10)
Next 30
Previous 30

Add a snippet!