1. 程式人生 > >2017京東實習生筆試題(一)

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;  結果又是什麼呢?

你知道思路嗎?