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.8 (297)
Count number of bits in a numberNaren Bala C or C++ANSI5.9 (60)
Create a new file under linuxChol Nhial 7.4 (587)
Creating, printing and free linked listsSyed Rafey Husain CANSI4.8 (78)
Distanceprog-bman C++ANSI5.6 (239)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI4.5 (77)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI5.3 (138)
euler approximation methoderic mbakop C or C++ANSI5.6 (329)
Eventhandling macro for classesToolsDevler 7.4 (555)
Example of polymorphismAli Nawkhas Murad C++ANSI5.7 (260)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI6.0 (190)
Failproof xor (en/de)cryptionyzb3 CANSI5.3 (196)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI5.4 (152)
Find the minimum distance between two linesGiacomo C or C++ANSI4.3 (78)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple6.5 (150)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI4.8 (88)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI5.5 (103)
friend function exampleAli Nawkhas Murad C++ANSI6.6 (484)
Function pointer to member function of classselvam C++ANSI5.1 (75)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.7 (145)
GetLastError error lookup toolKen Fitlike CWindows5.4 (245)
GotoXYStack Overflow C*nix5.7 (496)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.3 (94)
Implementing a directory listing on LinuxJoshith C*nix5.1 (89)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI5.2 (144)
Integer Partitions from 1 to NChristopher Brown 7.4 (553)
Integer subset generatortreenef C++ANSI6.1 (50)
Knuth-Morris-Pratt (KMP) String Search AlgorithmSyed Rafey Husain C or C++ANSI6.6 (933)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (98)
Menu driven program in c programmingcampus 7.4 (764)
Next 30
Previous 30