Archive for the ‘C Programming’ Category

Control structures and statements in C and C++

Control structures form the basic entities of a “structured programming language“. We all know languages like C/C++ or Java are all structured programming languages. Control structures are used to alter the flow of execution of the program.  Why do we need to alter the program flow ? The reason is “decision making“! In life, we may be given with a set of option like doing “Electronics” or “Computer science”. We do make a decision by analyzing certain conditions (like our personal interest, scope of job opportunities etc). With the decision we make, we alter the flow of our life’s direction….

Read More

Quick Sorting algorithm with example code in C/C++/Java languages

We have seen 3 simple sorting algorithms already 1) Bubble Sorting 2) Selection Sorting and finally Insertion sorting. All these algorithms were so simple to understand and were easy to implement as a program in C/C++ or even Java. But at the same time all 3 of them were too inefficient.  Their execution time was of the order of n*n, where n is the number of elements to be sorted. In practice, these simple sorting algorithms are seldom used.  Quick sort is an improved sorting algorithm developed by Tony Hoare (C.A.R Hoare) in 1960, at the  age of 26, while…

Read More

Insertion sorting algorithm with example in C/C++/Java languages

So far we have seen 2 sorting algorithms:- 1) Bubble sorting and 2) Selection sorting. Now in this article, we are analyzing insertion sort algorithm with its example code suitable for C/C++/Java programming languages. I recommend you go through above articles of Bubble sorting and Selection sorting before reading further.  Insertion sorting algorithm sorts one element at a time. It begins by sorting the first 2 elements in order. In the next step, it takes the third element and compares it against the first two sorted elements. Exchanges are made if necessary and the 3 elements will be sorted with respect to…

Read More

Selection Sort in C/C++/Java programming languages

In the previous article, we have analysed Bubble sort algorithm and it’s implementation in C programs. In this article we are going to see another sorting algorithm, named, Selection sorting. Just like “Bubble sort”, selection sort is also considered as an inefficient sorting algorithm. If you are curious to know the reason for this, please read the article about Bubble sort carefully. The number of comparisons involved in an average bubble sort is 0.5*(n*n-n). Same is the index for Selection sort too. Note:- Since the algorithm is implemented with the help of 2 FOR loops only, it can be used…

Read More

Difference between Procedure Oriented(POP) and Object Oriented Programming(OOP)

We all know there exist 2 approaches to write a program – 1) Procedure oriented programming (POP) and 2) Object oriented programming (OOP). You can write a program in either way but there are notable differences between both approaches. These 2 approaches are the result of software development evolution over many decades. Since the invention of computer, many approaches and methods have been tried to write a program. It includes methods like a) Top-Down programming b) Bottom-Up programming c) Modular programming  d) Structured programming etc. The basic purpose or the basic aim of all these methods were same – “to…

Read More

Bubble Sorting with example in C/C++/Java

Bubble sorting is one of the simplest sorting algorithm that we can use to sort an array or a structure. Though it is so simple to implement in a C program, bubble sort is also considered as an inefficient sorting algorithm. Bubble sort comes handy in cases where the total number of elements to be sorted is so small (may be in the 100′s range). When the data size is large/huge bubble sort is seldom used in practical programming world. Let’s analyse bubble sort algorithm in detail by implementing it as a C program.  Note:- Since the algorithm is implemented with the help of 2 FOR…

Read More

Void pointers in C

In this article we are learning about “void pointers” in C language. Before going further it will be good if you refresh about pointers by reading – Introduction to pointers in C.  A pointer variable is usually declared with the data type of the “content” that is to be stored inside the memory location (to which the pointer variable points to). Ex:- char  *ptr;       int  *ptr;      float  *ptr; A pointer variable declared using a particular data type can not  hold the location address of variables of other data types. It is invalid and will result…

Read More

Introduction to pointers in C

The basic purpose of developing a C programming tutorial for this website – CircuitsToday – is to make it useful for people who wish to work with embedded systems. Really good C programming skill is an essential to work with embedded systems and “Pointers” is the most important concept in C that should be mastered by an embedded systems programmer. “Pointers” are so important because it enables a programmer to work directly with memory of the system. Memory of a system is organized as a sequence of byte sized locations (1 byte = 8 bits). If the total memory of…

Read More

Compilers vs Interpreters – An overview of the differences

It is a general notion that people try to classify programming languages as either “compiled” language or “interpreted” language. Even experienced programmers tend to get confused here! But the fact is, programming languages are neither “compiled” nor “interpreted” types. They can be both at the same time. Compiling or interpreting -both are 2 different ways of implementing the same program written using a programming language. A program written in C language can either be compiled or can be interpreted. Same is the case with Java or any other programming languages. The only requirement is, we need a C or Java…

Read More

How to use Turbo C/C++ to run your first C program

There is no one in this world who is born as a programmer To write efficient programs using any languages you have to learn it by doing! You have to write as many different programs using as many different algorithms. You have to break codes, make errors, debug errors and sometimes you have to approach the same problem using 2 or 3 different logics. To learn “C language” efficiently, you must write a lot of different C programs using the concepts of C language. To do this you need a good compiler for C language setup on your computer. Turbo…

Read More