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)
this one is better because a potential overflow (of the + operation) is avoided 5.6 (9)
Output console text with type-writer effect.Michael Brandon Miller 5.6 (9)
A portable card deck class with shufflingSlyMaelstrom C++ANSI5.6 (9)
Integer Partitions from 1 to NChristopher Brown 5.6 (9)
Distanceprog-bman C++ANSI5.5 (184)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.4 (10)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI5.3 (6)
Integer subset generatortreenef C++ANSI5.3 (10)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.3 (11)
simple StopWatch with roundtrip timeNickMa 5.1 (8)
Quick-sort using vector and iterator in STLJianbao Tao 5.1 (8)
Palindrome FunctionJason Weeks 5.1 (8)
String FunctionsDominic Vonk 5.1 (8)
String FunctionsDominic Vonk 5.1 (8)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
A singly linked list with a sentinel implementationyzb3 CANSI4.9 (21)
Previous 30

Add a snippet!