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++ANSI7.2 (25)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.6 (345)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.1 (202)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.6 (358)
Another merge sort of integer listManoj CANSI6.3 (11)
Output console text with type-writer effect.Michael Brandon Miller 5.7 (6)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.8 (156)
Print variables with file and line number for debuggingmike lear C++ANSI6.1 (12)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
Shorter version of gotoxyNedeljko CLinux7.9 (34)
simple StopWatch with roundtrip timeNickMa 5.0 (5)
A game setup for DirectXPaul D C or C++ANSI6.3 (231)
Calculates 1 variable statisticsPaul Kennedy C++ANSI5.8 (9)
A code template for OpenGL / GLUTPerspective C or C++ANSI6.0 (220)
Distanceprog-bman C++ANSI5.5 (184)
Template Calculatorprog-bman C++ANSI6.1 (275)
Menu driven program in c programmingcampus 5.7 (6)
Tic-TacToeptrs 5.7 (6)
Generate a spiral matrix for n elementsRaza C or C++ANSI6.6 (24)
a simple clockrichmond caesar CANSI6.5 (428)
Color header for Windows that integrates with coutSang-drax C++Windows6.4 (207)
Word wrap functionSean Hubbard CANSI8.4 (60)
Function pointer to member function of classselvam C++ANSI8.6 (11)
Find the Prime Factors of Given NumberSHINE AIYYAPPAN CANSI7.4 (18)
Find The Sum of Digits of a Given NumberSHINE AIYYAPPAN CANSI8.2 (28)
Pascals Triangle Using Combination Function of IndicesSHINE AIYYAPPAN CANSI8.5 (64)
A portable card deck class with shufflingSlyMaelstrom C++ANSI5.6 (9)
GotoXYStack Overflow C*nix6.3 (338)
Creating, printing and free linked listsSyed Rafey Husain CANSI6.4 (8)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI5.3 (6)
Next 30
Previous 30

Add a snippet!