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

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;
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The output of the code will be 1.

Here's the step by step explanation:

  1. The variable num is initialized with the value 2 and count is initialized with 0.
  2. The while loop will continue as long as num is not equal to 0.
  3. 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

This problem has been solved

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 = &num; 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;    }

1/3