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)
An example of simple priority queue using linked lists.Ali Nawkhas Murad C++ANSI5.3 (138)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.2 (13)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI5.2 (113)
GetLastError error lookup toolKen Fitlike CWindows5.2 (210)
Word wrap functionSean Hubbard CANSI5.2 (162)
Simple swapping heapsortyzb3 C or C++ANSI5.1 (161)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.1 (181)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple5.1 (62)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI5.1 (60)
Shorter version of gotoxyNedeljko CLinux5.1 (60)
binary addition using stack in STLanmol C++ANSI5.0 (101)
Failproof xor (en/de)cryptionyzb3 CANSI5.0 (152)
Calculates the closest point to a segmentAdrián Deccico C or C++ANSI4.9 (159)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI4.9 (104)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows4.9 (97)
Integer subset generatortreenef C++ANSI4.9 (11)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI4.9 (98)
Initial values for static multidimensional arrayAli Nawkhas Murad C or C++ANSI4.8 (101)
string to bitstring, bitstring to stringEsa Karjalainen CANSI4.8 (54)
A singly linked list with a sentinel implementationyzb3 CANSI4.7 (22)
Count number of bits in a numberNaren Bala C or C++ANSI4.7 (10)
Simple example for using thousand separator (,)Ali Nawkhas Murad C++ANSI4.6 (93)
An example of Exception HandlingAli Nawkhas Murad C++ANSI4.6 (94)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.4 (53)
Another merge sort of integer listManoj CANSI4.1 (47)
Implementing a directory listing on LinuxJoshith C*nix4.1 (47)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI4.0 (52)
Function pointer to member function of classselvam C++ANSI4 (40)
Macro to swap nibble of BYTET Sailesh C or C++ANSI3.9 (47)
An example use of a function pointerJayesh C++ANSI3.6 (43)
Next 30
Previous 30

Add a snippet!