What will be the output of the following code?int num = 2;int count=0;while(num!= 0){if ( num & 01)count ++;num >>=1;}cout<< count;return 0;
Question
Solution 1
The output of the code will be 1.
Here's the step by step explanation:
- The variable
num
is initialized with the value 2 andcount
is initialized with 0. - The
while
loop will continue as long asnum
is not equal to 0. - Inside the loop, the
if
statement checks if the bitwise AND ope Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study prob
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solv
Similar Questions
What will be the output of the following code?int num = 2;int count=0;while(num!= 0){if ( num & 01)count ++;num >>=1;}cout<< count;return 0;
What happens if we compile the following code?12345678#include <stdio.h>int main() { int num = 42; int *ptr = # printf("%d", *ptr); return 0;}
What will be the output of the following code? int i = 1;while(i<10){ if (i / 2 == 2) cout << i << “ ”;i++;}
What is the output of the following code snippet? int num = 10; System.out.println(num++); System.out.println(++num);
What will be the output of the following code? int i = 0; while(i!=15){ cout << i << " "; i = i + 5; }