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)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI5.3 (112)
Three Dimension Coordinate Systems ConverterAli Nawkhas Murad C++ANSI5.3 (108)
GetLastError error lookup toolKen Fitlike CWindows5.2 (209)
Generate a spiral matrix for n elementsRaza C or C++ANSI5.2 (76)
An example of simple priority queue using linked lists.Ali Nawkhas Murad C++ANSI5.2 (135)
Word wrap functionSean Hubbard CANSI5.2 (160)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple5.2 (61)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI5.2 (59)
Simple swapping heapsortyzb3 C or C++ANSI5.2 (160)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.1 (180)
Shorter version of gotoxyNedeljko CLinux5.1 (59)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
binary addition using stack in STLanmol C++ANSI5.1 (100)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI5.0 (103)
Failproof xor (en/de)cryptionyzb3 CANSI5.0 (151)
Calculates the closest point to a segmentAdrián Deccico C or C++ANSI5.0 (158)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows5.0 (96)
A singly linked list with a sentinel implementationyzb3 CANSI4.9 (21)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI4.9 (97)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI4.9 (100)
string to bitstring, bitstring to stringEsa Karjalainen CANSI4.8 (53)
Simple example for using thousand separator (,)Ali Nawkhas Murad C++ANSI4.6 (91)
An example of Exception HandlingAli Nawkhas Murad C++ANSI4.6 (92)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.5 (52)
Another merge sort of integer listManoj CANSI4.2 (46)
Implementing a directory listing on LinuxJoshith C*nix4.1 (46)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI4.1 (51)
Function pointer to member function of classselvam C++ANSI4.0 (39)
An example use of a function pointerJayesh C++ANSI3.6 (42)
Macro to swap nibble of BYTET Sailesh C or C++ANSI3.4 (42)
Next 30
Previous 30

Add a snippet!