2017京东实习生笔试题(一)

下面程序的返回值是什么?

#include "stdafx.h"
#include<iostream>
using namespace std;
int func(int x)
{
   int count = 0;
   while (x)
   {
     count++;
     x = x&(x - 1);
   }
  return count;
}
int main()
{
  cout << func(2015) << endl;
  return 0;
} 

如果cout<<func(9999)<<endl;  结果又是什么呢?

你知道思路吗?


你可能感兴趣的:(C++)