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++Windows4.9 (95)
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 6.4 (14)
Creating, printing and free linked listsSyed Rafey Husain CANSI2.3 (32)
Distanceprog-bman C++ANSI5.5 (184)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI2.5 (34)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI4.8 (96)
euler approximation methoderic mbakop C or C++ANSI5.5 (280)
Eventhandling macro for classesToolsDevler 6.4 (14)
Example of polymorphismAli Nawkhas Murad C++ANSI5.4 (172)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI5.5 (120)
Failproof xor (en/de)cryptionyzb3 CANSI5.5 (113)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI5.0 (103)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (35)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple4.1 (43)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI3.9 (45)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI5.2 (57)
friend function exampleAli Nawkhas Murad C++ANSI4.7 (66)
Function pointer to member function of classselvam C++ANSI4.0 (39)
Generate a spiral matrix for n elementsRaza C or C++ANSI4.1 (50)
GetLastError error lookup toolKen Fitlike CWindows5.2 (209)
GotoXYStack Overflow C*nix5.7 (389)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI2.8 (38)
Implementing a directory listing on LinuxJoshith C*nix2.8 (36)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI4.9 (100)
Integer Partitions from 1 to NChristopher Brown 6.4 (14)
Integer subset generatortreenef C++ANSI5.3 (10)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.1 (514)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (10)
Next 30
Previous 30

Add a snippet!