Enumerated Data Type in C Language

Bhanu Priya
Updated on 24-Mar-2021 14:24:31

3K+ Views

These are used by the programmers to create their own data types and define what values the variables of these datatypes can hold.The keyword is enum.SyntaxThe syntax for enumerated data type is as follows −enum tagname{    identifier1, identifier2, ……., identifier n };ExampleGiven below is an example for enumerated data type −enum week{    mon, tue, wed, thu, fri, sat, sun };Here, Identifier values are unsigned integers and start from 0.Mon refers 0, tue refers 1 and so on.ExampleFollowing is the C program for enumerated data type − Live Demo#include main ( ){    enum week {mon, tue, wed, thu, fri, ... Read More

Merge Two Arrays in C Language

Bhanu Priya
Updated on 24-Mar-2021 14:22:04

6K+ Views

Take two arrays as input and try to merge or concatenate two arrays and store the result in third array.The logic to merge two arrays is given below −J=0,k=0 for(i=0;i

C Program for Sparse Matrix

Bhanu Priya
Updated on 24-Mar-2021 14:20:46

44K+ Views

In a given matrix, when most of the elements are zero then, we call it as sparse matrix. Example − 3 x3 matrix1 1 0 0 0 2 0 0 0In this matrix, most of the elements are zero, so it is sparse matrix.ProblemCheck whether a matrix is a sparse matrix or not.SolutionLet us assume ZERO in the matrix is greater than (row * column)/2.Then, the matrix is a sparse matrix otherwise not.ProgramFollowing is the program to check whether the given matrix is sparse matrix or not − Live Demo#include #include int main(){    int row, col, i, j, a[10][10], count ... Read More

Difference Between Local and Global Variable

AmitDiwan
Updated on 24-Mar-2021 14:20:09

11K+ Views

In this post, we will understand the difference between local and global variables.Local variableIt is generally declared inside a function.If it isn’t initialized, a garbage value is stored inside it.It is created when the function begins its execution.It is lost when the function is terminated.Data sharing is not possible since the local variable/data can be accessed by a single function.Parameters need to be passed to local variables so that they can access the value in the function.It is stored on a stack, unless mentioned otherwise.They can be accessed using statement inside the function where they are declared.When the changes are ... Read More

Count Trailing and Leading Zeros in a Binary Number using C

Bhanu Priya
Updated on 24-Mar-2021 14:19:25

3K+ Views

To begin with, let us understand what are trailing zeros in a binary number.Trailing zerosThe position of zeros after first one from the least significant bit (LSB) is called as trailing zeros in binary number.Example104 is decimal numberBinary number of 104 is: (MSB) 1101000(LSB)Here, MSB refers to Most Significant Bit.LSB refers to Least Significant Bit.From LSB after the first bit set, there are three zero.The number of trailing zeros is three.ExampleFollowing is the program to count number of trailing zeros for a given number − Live Demo#include #include int main(){    int number, i, trail = 0, size;    printf("Enter a ... Read More

Rotate Bits for a Given Number in C

Bhanu Priya
Updated on 24-Mar-2021 14:18:20

3K+ Views

Consider the factors given below to write a C program to rotate the bits for a given number.Rotating the bit from left to right or right to left.In left rotation, the bits are shifted from left to right.In right rotation, the bits are shifted from right to left.Take a number and try to rotate either left or right based on user program.User has to enter the number rotation at run time along with a number.Program 1Following is the C program to apply left rotation for a given number. Live Demo#include #include int main(){    int number, rotate, Msb, size;    printf("Enter ... Read More

Difference Between Static and Dynamic Binding

AmitDiwan
Updated on 24-Mar-2021 14:17:55

2K+ Views

In this post, we will understand the difference between static binding and dynamic binding.Static BindingIt is resolved at compile time.It uses type of the class and fields.It uses private, final, and static methods and variables.Example: OverloadingDynamic BindingIt is resolved during run time.Virtual methods use this technique.It uses objects to resolve the binding.Example: Method overriding.

Difference Between Type Casting and Type Conversion

AmitDiwan
Updated on 24-Mar-2021 14:17:37

4K+ Views

In this post, we will understand the difference between type casting and type conversion.Type castingA data type is converted to another data type using the casting operator by the developer.It can be applied to any compatible data types and incompatible data types.The casting operator is required to cast a data type to another type.The destination data type could be smaller than the source data type.It happens during the program design.It is also known as narrowing conversion since the destination data type may be smaller than the source data type.It is generally used in coding and competitive programming.It is efficient.It is ... Read More

Calculate Difference Between Two Time Periods in C

Bhanu Priya
Updated on 24-Mar-2021 14:16:13

4K+ Views

Enter the start and stop time with hours, minutes and seconds. Finally, we need to find the difference between start and stop time.The logic to find the difference between start and stop time is given below −while (stop.sec > start.sec){    --start.min;    start.sec += 60; } diff->sec = start.sec - stop.sec; while (stop.min > start.min) {    --start.hrs;    start.min += 60; } diff->min = start.min - stop.min; diff->hrs = start.hrs - stop.hrs;ExampleFollowing is the program to find difference between start and stop time − Live Demo#include struct time {    int sec;    int min;    int hrs; ... Read More

Difference Between Break and Continue in Programming

AmitDiwan
Updated on 24-Mar-2021 14:15:39

2K+ Views

In this post, we will understand the difference between break and continue statements.breakIt is used to terminate the enclosing loop like while, do-while, for, or switch statement where it is declared.It resumes control over the program until the end of the loop.It also helps with the flow of control outside the loop.It is used with ‘switch’ and ‘label’ since it is compatible.Following is the flowchart of break statement −continueIt helps skip the remaining part of the loop.It continues to execute the next iteration.It causes early execution of the next iteration of the enclosing loop.It can’t be used with ‘switch’ and ... Read More

Advertisements