GoogleTag

Google Search

[Programming] Question 12: Demonstrate multiplication by powers of 2 using left shift operator in C?

 

#include <stdio.h>

int main() {
	int num = 5;

	printf("Original number: %d\n", num);

	num = num << 3; // Multiply by 2^3 = 8

	printf("After multiplication by 8: %d\n", num);

	return 0;
} 

Inside the main() function:

- An integer variable num is initialized with the value 5.

- The original value of num is printed to the console.

- The num variable is left shifted by 3 bits using the `<<` operator, effectively multiplying it by 8 (2^3).

- The result after multiplication is printed to the console.



Featured Posts

SQL Interview Questions Topics

 SQL Topics to prepare for interviews,   SQL Basics: Introduction to SQL SQL Data Types DDL (Data Definition Language): C...

Popular Posts