有意思的一些东西

1 #include <stdio.h>
2 
3 int i = 1;
4 int main(){
5    int i = i;
6    printf("%d
", i);
7 }

上面这一段小代码,展示了C语言定义的一些东西,打印出来的值应该是未定义的值。main函数之外的定义为全局变量,而main函数内的定义是局部变量。

2.

#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(9999) << endl;
        return 0;
}

 这段代码其实就是检测输入值中包含二进制1的个数。

原文地址:https://www.cnblogs.com/javametro/p/5532312.html