The switch case in C is a multi-way decision-making statement which selects one of the several alternatives based on a set of fixed values for a given expression. The switch case is mainly used to replace multiple if-else
statements. The use of numerous if-else
statements causes performance degradation as several conditions need to be evaluated before a particular condition is satisfied. The general form of the switch statement is
[Read more…] about Switch Case in C
Data Structures in C
The data structures in c is a logical or mathematical model of a particular arrangement or organization of data. In other words, a data structures in c is a particular way of storing data in the computer’s memory so that it can be used easily and efficiently. Many different data structures might store the same data, each of which is suited to organize data differently. By analyzing the most frequent ways that your data is used, you can decide which data structure is appropriate. While designing a data structure, one must identify the logical structure of data in a particular application, accordingly choose the organization of data and find out various operations applied to it. [Read more…] about Data Structures in C
Difference between Compiler and Interpreter
Compilers and interpreters are translator programs (also called language processors) for converting high-level language into machine codes for the computer. Computer programs are usually written in languages of high-level. People can understand a high-level language. To clarify this, they contain words and phrases from commonly used languages such as English or other languages. Computers, however, cannot understand high-level languages like we humans. [Read more…] about Difference between Compiler and Interpreter
String Functions in C
In C, a string is a sequence of characters terminated by a null character (‘\0’). Strings can create using string-literals, which are sequences of characters with double quotation marks; for example, a string of literal “Computer Notes.”
The C library offers a wide array of functions for string operations. [Read more…] about String Functions in C
Factorial Program in C
Factorial Program in C: The factorial of a positive integer n, denoted by n!, is the product of all positive descending integers less than or equal to n: Syntax for factorial number is:
[Read more…] about Factorial Program in C
Dynamic Memory Allocation in C
While declaring arrays, we noticed that the array size must be specified at compile-time and cannot change during the program’s duration. The actual size needed by the array is often not known until runtime because the amount of space required depends upon input data.
This approach is although simple but has many disadvantages. With this approach, a lot of memory is wasted when the number of elements required is minimal. It is also incapable of handling problems large than the size specified. So the solution to this problem is to allocate memory to the array dynamically so its size can be changed during runtime. This process of memory allocation to variables at run time is called dynamic memory allocation in C.
C Dynamic Memory allocation is performing manual memory management by a group of functions in the standard C library, i.e. malloc, realloc, calloc and free. These functions are defined in stdlib.h header file. [Read more…] about Dynamic Memory Allocation in C
Merge Sort in C
Merge Sort in C is a divide and conquer algorithm which John von Neumann developed in 1945. We divide the data into smaller pieces, recursively conquer each piece and merge the result into the final result until the original list is rebuild sorted. This tutorial will help you to understand Merge Sort In C in detail. [Read more…] about Merge Sort in C
Matrix Multiplication in C
Matrix Multiplication in C: You can add, deduct, multiply, and divide two matrices (two-dimensional arrays). To do this, we inputs the size (rows and columns) of two matrices using the user’s data. The number of columns of the first matrix must be equal to the rows of the second matrix to multiply two matrices. Then we multiply the entered matrices of the user. [Read more…] about Matrix Multiplication in C
File Handling in C
In this tutorial, you will learn about file handling in C. You will learn to handle standard I/O in C using fprintf(), fscanf(), fread(), fwrite(), fseek() etc. with the help of examples. [Read more…] about File Handling in C
Prime Number Program in C
In this tutorial, We will check a given positive integer N. The task is to write a C program to check if the number is prime or not. [Read more…] about Prime Number Program in C
Selection Sort in C
The Selection sort in C is a simple sorting algorithm used for sorting an array by repeatedly iterates. It first finds the smallest element from the unsorted list of elements, swaps with the first position element, finds the second smallest element, swaps with the second position element, this process continues till all the elements are sorted. This method based on the following principle: [Read more…] about Selection Sort in C
Binary Search in C
In this tutorial, We will learn Binary Search in C with practical implementation. A binary search (also known as half-interval search or logarithmic search) is similar to a linear search, but It’s a technique that is faster than a linear search except for small arrays. Binary search implemented only for sorted array or list. If the array elements not sorted, we need to sort them first. [Read more…] about Binary Search in C
What is Insertion Sort in C with Example
Insertion Sort in C is a comparison-based sorting algorithm that arranges numbers of an array in order. It is stable, adaptive, in-place and incremental in nature. The insertion sort is useful for sorting a small set of data. It sorts smaller arrays faster than any other sorting algorithm. But, it is impractical to sort large arrays. [Read more…] about What is Insertion Sort in C with Example
What is Linked List in C with example?
In this tutorial, We will learn about the linked list in C, and it’s implementation. The array data structure has some limitations. Firstly, the array’s size is fixed due to which either a lot of memory is wasted if we have very few elements in the array or undesirable results are produced if the number of elements in the array exceeds the limits of the defined size. Secondly, the insertions and deletions of elements are complex and inefficient processes as potentially a large number of elements need to be shifted to make room for a new element or to delete an existing element. So to overcome these severe limitations, another data structure known as Linked List is used. [Read more…] about What is Linked List in C with example?
What is storage classes in C with example?
Every variable in C is associated with a storage class in addition to its data type and name.
A variable’s storage class specifier tells us :
1. The place where the variable may be stored: Memory or CPU registers.
2. The initial default value of the variable, if the initial value is not specified explicitly in the program,
3. The scope of a variable. It specifies the area or portion of the program where it can access. A local variable’s scope is limited to the function in which it declares, whereas the global variable is visible throughout the program.
Limiting the variable’s scope is very useful when several programmers are working on different pieces of the same program. On limiting the scope of the variables to the block of code in which is declared, there will be no need to worry about conflicting variables of the same name used by others in other parts of the program.
4. The lifetime, i.e. how long the variable stays in memory. The lifetime of a variable is a period during which memory associates with a variable. It is the duration between the creation of the variable and its destruction.
A local variable’s lifetime is when a function is called, in which the variable declares till the end of the execution of that function call. A global variable’s lifetime is the program’s period of execution as it declares outside the function.
[Read more…] about What is storage classes in C with example?
What is bubble sort in C with example?
Bubble sort in C is the most straightforward sorting algorithm called a sinking sort, and It works by repeatedly moving the largest elements to the highest index position in the array (if elements are to arranged in ascending order). It requires (n-1) passes to sort an array. For this, it uses several passes through the array and in each pass, the largest element searches its proper position in the sorted array. Bubble sort is not difficult to implement, and it’s fast enough once you have small data sets. The bubble sort algorithm has the same efficiency as the selection sort algorithm. [Read more…] about What is bubble sort in C with example?
Difference between C and C++
In this tutorial, we shall explain the main difference between C and C++ languages. As we all know both C and C++ are programming languages and C++ language is a superset of the C language. [Read more…] about Difference between C and C++
What is difference between structure and union in C with example?
In C, the datatype is data transmitted between the developer and the compiler in which the developer informs the compiler about which type of data stored and how much space it needs in the memory. [Read more…] about What is difference between structure and union in C with example?
What is linear search in C language?
In this tutorial, we will understand the concept of “Linear search in C“, we’ll write a c program for linear search that searches for an element in an array using a Linear Search Algorithm. Before we proceed throughout the program, let’s see what is meant by linear search, advantages and disadvantage of linear search. We’ll talk about more linear search and then code a program in C language. [Read more…] about What is linear search in C language?
What is an Armstrong Number in C language?
In this Armstrong Number in C tutorial, we will write a C program for armstrong number.
An Armstrong number or Narcissistic number is an n-digit number equivalent to the sum of digits raised to the nth power of digits from the number. A few Armstrong numbers are: 0, 1, 2, 3, 153, 370, 407, 1634, 8208, etc.
[Read more…] about What is an Armstrong Number in C language?
Call by value and Call by reference in C
There are two parameter passing methods passing (or calling) data to functions in C language, i.e., Call by Value or Call by Reference (also Called pass by value and pass by reference). The most significant distinction between call by value and call by reference is that in the call by value, passing an actual value of the parameter. While, in a call by reference, passing the reference of the parameter; hence some change made to formal arguments will also reflect in actual arguments. [Read more…] about Call by value and Call by reference in C