The best way to learn any programming language is by practicing examples. This source code section features a diverse collection of programming examples and source code snippets written C, C++ and other programming languages.
The examples includes practical implementations, tutorials, and demonstrations aimed at helping programmers enhance to enhance their programming skills.
Table of Contents
- C Programming Source Code
- C++ Programming Source Code
- JavaScript Source Code
- PHP Code Snippets
- Java Source Code
C Programming Source Code
- LRU and FIFO L1 Cache Implementation using CThis is a C program to demonstrate cache mechanism by simulating a cache in C. The source code can run in any C Compiler with minor modifications if required. It can run on real memory traces as input to your cache simulator. We have implemented two cache replacement policies i.e. least recently used (LRU) and First-in first-out (FIFO) replacement policies.
- Random Number Generation in C/C++: Tricks for Generating, Seeding, and Working with Random NumbersC Standard Library provides two different methods to generate random numbers. They are: rand() and srand().
- C Algorithms LibraryThis article is about a collection of common Computer Science algorithms which may be used in C projects. The C Programming Language has a much smaller Standard Library as compared to other more modern programming languages such as Java or Python. The library provides a basic set of mathematical functions, string manipulation, type conversions, and file and console-based I/O.
- The “Hello, World!” Program in CThis is a simple “Hello, World!” C program to display “Hello, World!” text on the computer screen or display device. Typically, the best way to learn programming is by writing… Read more: The “Hello, World!” Program in C
- C Implementation of Base64 Encoding and DecodingBase64 encoding and decoding schemes are commonly used to encode binary data. Normally this is required when textual data needs to be transferred over the network or similar media and make sure that data is transferred without any modification. Base64 is commonly used in a number of applications, including email via MIME, and storing complex data in XML. This is a very simple implementation of base64 encoding and decoding in C programming language. There are number of C libraries available for encoding and decoding as well i.e. libb64, OpenSSL Base64, Apple’s Implementations, arduino-base64 etc.
- Porter’s Algorithm in COriginally written in 1979 at Computer Laboratory, Cambridge (England), it was reprinted in 1997 in the book “Readings in Information Retrieval”. Initially it was written in BCPL language. Here is the list of implementations in other programming languages including C, Java and Pearl implementations done by author himself.
C++ Programming Source Code
- C++ Code – Wave File Converter from Text FileThis C++ program is capable of turning a text file describing the notes of a piece of music into an audio file (.wav). The program reads the contents of the input file i.e. input.txt, constructs Song, Voice and Note objects… Read more: C++ Code – Wave File Converter from Text File
- Vigenere Encryption and Decryption in C++The Vigenere cipher is a method of encrypting or decrypting alphabetic text by using a series of interwoven Caesar ciphers (Caesar Shift), based on the letters of a keyword. In cryptography, Caesar shift is one of the simplest known encryption techniques. It employs a form of polyalphabetic substitution, which is using multiple substitution alphabets.
- C++ Program to Solve the Quadratic EquationThis program will solve quadratic equations. It accepts coefficients of a quadratic equation from the user i.e. a, b and c and displays the roots. To compile the program name it quadratic_solver.cpp then type g++ -o quadratic_solver quadratic_solver.cpp You may need to use math.h like this: #include if you are using windows C++ programming software. (I tried it without the math.h and got an “undeclared identifier” error)
- C++ “Hello World” ProgramTypically, the best way to learn programming is by writing code. The first program beginners write is “Hello, World!” which is often used to illustrate the syntax of a programming language. You can take a look at the list of Hello World Programs in 300 Programming Languages to see how “Hello, World!” looks like in different programming languages.
- Add time using structures in C++This is a C++ implementation of adding time using structures. A structure is a convenient tool for handling a group of logically related data items. Structure help to organize complex data is a more meaningful way. It is powerful concept that we may after need to use in our program Design.
- Common Text Transformation LibraryCommon Text Transformation Library, CTTL for short, is a set of C++ classes and functions to understand and modify text data. The library implementation is based on STL classes and algorithms. The library provides components for creating lexical analyzers making… Read more: Common Text Transformation Library
JavaScript Source Code
- Difference Between [] and {}: Arrays vs. Objects in JavaScriptIn JavaScript, we use braces {} for creating an empty object and brackets [] for creating an empty array. I find the Developer console in Mozilla Firefox or Google Chrome more convenient to print out any object and study the details.
- JavaScript Program to Show Current Time In Various FormatsThis is a small script that can display the current time in “Military Time” format or “12 Hour Time” format with the push of a button. It shows two radio buttons to change the time format and a text box to display the time.
- JavaScript Program to Show Date and TimestampThis is a simple JavaScript Program to show Date and Time Stamp on a webpage. In this script we define a JavaScript function named getFormattedDateTime. This function uses the Date object to get the current date and time. It then formats them into a human-readable string.
PHP Code Snippets
- How to Send Email using PHPA detailed guide on PHP mail sending options with examples of using the built-in mail function(), PHPMailer, Symfony, and third-party mail service providers such as Amazon SES, SendGrid and GetResponse.
- Search the LDAP Directory in PHPThis PHP code connects to an LDAP server, performs a search for entries with the last name and then sorts and prints them alphabetically. The sorting is done by a custom function called compareEntry, which compares entries based on last names and first names. It uses the LDAP functions to communicate with the server and showcases basic error handling.
- Calculating the Greatest Common Denominator (GCD) in PHPThis PHP code defines a function called gcd that calculates the greatest common denominator (GCD) of a list of integers by using a brute-force approach and later efficient and widely-used method called Euclidean Algorithm.
Java Source Code
- Java Program to Demonstrate the Use of Linked ListThis is a very simple implementation of linked list in java programming language. Very nice and well commented java source code for beginners.
- Java Program to Show Stack ImplementationThis is a simple Java program to demonstrate the Stack data structure implementation. This code provides a simple implementation of a stack with basic operations (push, pop, and isEmpty).
- Stack Implementation with ArrayThis java code implements stack functionality by using arrays. It can Pop and Push an item in stack with the help of array. The item can only be an integer number and internally the java program uses arrays to maintain items in stack.




















