Found 33676 Articles for Programming

C program for Addition and Multiplication by 2 using Bitwise Operations.

Bhanu Priya
Updated on 25-Mar-2021 08:06:05

1K+ Views

Bitwise operators operate on bits (i.e. on binary values of on operand)OperatorDescription&Bitwise AND|Bitwise OR^Bitwise XORRight Shift-One's complementBitwise ANDaba & b000010100111Bitwise ORaba | b000011101111Bitwise XORaba ^ b000011101110ExampleFollowing is the C program for addition and multiplication by 2 with the help of bitwise operators − Live Demo#include main(){    int a;    printf("Enter a");    scanf("%d",&a);    printf("%d*2=%d ",a,a1); }OutputWhen the above program is executed, it produces the following output −Run 1: Enter a 45 45*2=90 45/2=22 Run 2: Enter a 65 65*2=130 65/2=32

C program to print area of triangle, square, circle, rectangle and polygon using switch case.

Bhanu Priya
Updated on 10-Dec-2024 13:25:31

50K+ Views

Problem Write a program to calculate the area of triangle, square, circle, rectangle and polygon by using the switch case. Solution Based on case number, the area of triangle, square, circle, rectangle and polygon is calculated. The logic used to find area of triangle is as follows − Enter sides of a triangle a, b, c s=(float)(a+b+c)/2; area=(float)(sqrt(s*(s-a)*(s-b)*(s-c))); The logic used to find area of square is as follows − Enter the side of square at runtime. area=(float)side*side; The logic used to find ... Read More

Write a C program for guessing the number game.

Bhanu Priya
Updated on 25-Mar-2021 07:29:28

2K+ Views

ProblemIn a program a number is already initialized to some constant. Here, we have to ask the user to guess that number which is already in the program. For this, we need to provide some clues for every time the user entering the number.SolutionThe logic that is used to guess the number is as follows −do{    if(num==guess){       flag=0;    } else if(guess

C program to count a letter repeated in a sentence.

Bhanu Priya
Updated on 25-Mar-2021 07:24:11

6K+ Views

ProblemWrite a program to count a letter, which is entered by the user at console. How many times that letter is repeated in a sentence need to be printed on screen by using strlen() function.SolutionThe logics we used to count a letter are as follows −Asking the user to enter a sentence at runtime.printf("Enter a sentence"); gets(str);Asking the user to enter a letter at runtime.printf("Enter a character to check how many times it is repeating"); scanf("%c", &c);The logic to count the letter in a sentence is as follows −for(i=0;iRead More

What is C unconditional jump statements?

Bhanu Priya
Updated on 25-Mar-2021 07:20:59

11K+ Views

C programming language allows jumping from one statement to another. It also supports break, continue, return and go to jump statements.breakIt is a keyword which is used to terminate the loop (or) exit from the block.The control jumps to next statement after the loop (or) block.break is used with for, while, do-while and switch statement.When break is used in nested loops then, only the innermost loop is terminated.The syntax for break statement is as follows −ExampleFollowing is the C program for break statement − Live Demo#include main( ){    int i;    for (i=1; i

What do you mean by odd loops in C language?

Bhanu Priya
Updated on 07-Jan-2025 10:59:03

3K+ Views

In C programming language, control statements are used to repeat a set of statements, while conditional statements are used for decision-making. These decision-making statements are also used to determine one or more conditions that decides whether a set of statements should be executed. They are as follows − for loop while loop do-while loop For loop and while loop, the condition specifies the number of times the loop can be executed. The "for loop" The for loop is an entry-controlled loop that executes statements until the ... Read More

Difference Between Constructor and Destructor

Kiran Kumar Panigrahi
Updated on 31-Oct-2023 03:35:33

33K+ Views

In object oriented programming, both constructor and destructor are the member functions of a class having the same name as the class. A constructor helps in initialization of an object, i.e., it allocates memory to an object. On the other hand, a destructor deletes the created constructor when it is of no use which means it deallocates the memory of an object. In this article, we will discuss the important differences between constructors and destructors. Let's start with some basic concepts of constructors and destructors. What is a Constructor? A constructor is a member function of a class that initializes ... 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

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

Advertisements