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)
A game setup for DirectXPaul D C or C++ANSI6.3 (231)
Checking for powers of twoWebmaster C or C++ANSI6.4 (267)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.1 (202)
A code template for OpenGL / GLUTPerspective C or C++ANSI6.0 (220)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI5.9 (14)
Simple integer binary search example source codeSyed Rafey Husain C or C++ANSI5.3 (6)
Macro to swap nibble of BYTET Sailesh C or C++ANSI5.9 (9)
One line swap of integersabhilash C or C++ANSI8.2 (99)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple7.6 (15)
Generate a spiral matrix for n elementsRaza C or C++ANSI6.6 (24)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI6.3 (12)
Distanceprog-bman C++ANSI5.5 (184)
View the contents of a directoryfinnepower C++Windows6.9 (160)
Permutation GeneratorTreenef C++ANSI7.4 (333)
An example use of a function pointerJayesh C++ANSI7.3 (14)
Calandar generator printing a full calendar for any yearJoe C++ANSI7.2 (33)
View the format of IEEE 754 floating point numbersAli Nawkhas Murad C++ANSI9.0 (63)
Templated queue classAli Nawkhas Murad C++ANSI8.6 (60)
Example of polymorphismAli Nawkhas Murad C++ANSI8.8 (81)
Print variables with file and line number for debuggingmike lear C++ANSI6.1 (12)
Simple Windows Socket Server ExampleJahan Addison C++Windows7.4 (55)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI7.8 (47)
An example of simple priority queue using linked lists.Ali Nawkhas Murad C++ANSI8.2 (60)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.6 (345)
Template Calculatorprog-bman C++ANSI6.1 (275)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI8.4 (53)
Function pointer to member function of classselvam C++ANSI8.6 (11)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI8.6 (53)
Pascal's TriangleAli Nawkhas Murad C++ANSI8.4 (81)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI8.7 (63)
Next 30
Previous 30

Add a snippet!