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)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.5 (52)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (445)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.6 (229)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.7 (446)
Another merge sort of integer listManoj CANSI2.8 (36)
Output console text with type-writer effect.Michael Brandon Miller 8.6 (337)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.1 (180)
Print variables with file and line number for debuggingmike lear C++ANSI2.7 (36)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
Shorter version of gotoxyNedeljko CLinux5.1 (59)
simple StopWatch with roundtrip timeNickMa 8.6 (336)
A game setup for DirectXPaul D C or C++ANSI5.5 (282)
Calculates 1 variable statisticsPaul Kennedy C++ANSI2.3 (33)
A code template for OpenGL / GLUTPerspective C or C++ANSI7.3 (495)
Distanceprog-bman C++ANSI5.5 (185)
Template Calculatorprog-bman C++ANSI5.4 (330)
Menu driven program in c programmingcampus 8.6 (337)
Tic-TacToeptrs 8.6 (337)
Generate a spiral matrix for n elementsRaza C or C++ANSI4.4 (54)
a simple clockrichmond caesar CANSI5.6 (563)
Color header for Windows that integrates with coutSang-drax C++Windows5.4 (256)
Word wrap functionSean Hubbard CANSI5.4 (116)
Function pointer to member function of classselvam C++ANSI4.0 (39)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI4.1 (49)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI5.2 (59)
Pascals Triangle Using Combination Function of IndicesSHINE AIYYAPPAN CANSI7.4 (386)
A portable card deck class with shufflingSlyMaelstrom C++ANSI8.7 (269)
GotoXYStack Overflow C*nix5.8 (403)
Creating, printing and free linked listsSyed Rafey Husain CANSI2.9 (35)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI5.3 (6)
Next 30
Previous 30

Add a snippet!