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++ANSI5.5 (282)
Checking for powers of twoWebmaster C or C++ANSI5.7 (323)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.6 (229)
A code template for OpenGL / GLUTPerspective C or C++ANSI7.3 (495)
how to implement strlwr in CSyed Rafey Husain C or C++ANSI3.0 (39)
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++ANSI6.3 (13)
One line swap of integersabhilash C or C++ANSI5.3 (194)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple4.5 (49)
Generate a spiral matrix for n elementsRaza C or C++ANSI4.4 (54)
Merge sort of an integer listBibhubrata Narendra C or C++ANSI2.9 (37)
Distanceprog-bman C++ANSI5.5 (185)
View the contents of a directoryfinnepower C++Windows5.5 (208)
Permutation GeneratorTreenef C++ANSI5.8 (463)
An example use of a function pointerJayesh C++ANSI3.5 (41)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.3 (123)
View the format of IEEE 754 floating point numbersAli Nawkhas Murad C++ANSI7.9 (348)
Templated queue classAli Nawkhas Murad C++ANSI5.5 (115)
Example of polymorphismAli Nawkhas Murad C++ANSI5.5 (185)
Print variables with file and line number for debuggingmike lear C++ANSI2.7 (36)
Simple Windows Socket Server ExampleJahan Addison C++Windows5.0 (129)
Calandar generator (based on snippet by Joe) printing a calendar for any yearTyler Veness C++ANSI8.2 (324)
An example of simple priority queue using linked lists.Ali Nawkhas Murad C++ANSI5.1 (125)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (445)
Template Calculatorprog-bman C++ANSI5.4 (330)
An example of using the same variable name in different scopesAli Nawkhas Murad C++ANSI5.0 (103)
Function pointer to member function of classselvam C++ANSI4.0 (39)
Find size and storage capacity of primitive data typesAli Nawkhas Murad C++ANSI5.1 (107)
Pascal's TriangleAli Nawkhas Murad C++ANSI7.4 (404)
Examples of dynamic multidimensional arraysAli Nawkhas Murad C++ANSI5.6 (124)
Next 30
Previous 30

Add a snippet!