版权声明:本文为博主原创文章,未经博主同意不得转载。

https://blog.csdn.net/cnxxrj/article/details/29813109

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
#include <stdio.h>

int i = 1;

int main(void)
{
	int i = i;
	int a = a;

	printf("%d\n",i);	
	printf("%d\n",a);	

	return 0;
}


输出结果:


面试宝典之程序设计基本概念 随笔 第1张

------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

int main(void)
{
	int x = 2, y, z;
	x *= (y = z = 5); cout << x << endl;
	z = 3;

	x == (y = z); cout << x << endl;
	x = (y == z); cout << x << endl;
	x = (y&z);    cout << x << endl;
	x = (y && z); cout << x << endl;
	y = 4;
	x = (y | z);  cout << x << endl;
	x = (y || z); cout << x << endl;

	return 0;
}

输出结果:

面试宝典之程序设计基本概念 随笔 第2张


注意:书上的结果缺少了最后面的那个1


-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

int func(int x){
	int count = 0;

	while(x){
		count ++;
		x = x&(x-1);
	}
	
	return count;
}

int main(void)
{
	cout << func(9999) << endl;
	return 0;
}

输出结果:

面试宝典之程序设计基本概念 随笔 第3张


由于9999的二进制为:


面试宝典之程序设计基本概念 随笔 第4张

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
using namespace std;

int main(void)
{
	int a, x;
	for (a = 0, x = 0; a <= 1 && !x++; a++){
		a++;
	}

	cout << a << x << endl;

	return 0;
}

面试宝典之程序设计基本概念 随笔 第5张

#include <iostream>
using namespace std;

int main(void)
{
	int a, x;
	for (a = 0, x = 0; a <= 1 && !x++;){
		a++;
	}

	cout << a << x << endl;

	return 0;
}

面试宝典之程序设计基本概念 随笔 第6张

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
	int b = 3;
	int i = 0;

	int arr[] = {6, 7, 8, 9, 10};
	signed int *ptr = arr;
	*(ptr++) += 123;

	printf("%d, %d\n", *ptr, *(++ptr));
	for (i = 0; i < 5; i++){
		printf("%d\n", arr[i]);
	}
	return 0;
}

结果为:

面试宝典之程序设计基本概念 随笔 第7张

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
	unsigned int a = 0xFFFFFFF7;
	unsigned char i = (unsigned char )a;
	char *b = (char *)&a;

	printf("%08x, %08x", i, *b);

	return 0;
}

结果为:

面试宝典之程序设计基本概念 随笔 第8张

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
//#include <stdio.h>
//#include <string.h>
//#include <conio.h>

using namespace std;

int main(void)
{
	float a = 1.0f;
	cout << (int )a << endl;
	cout << &a << endl;
	cout << (int &)a << endl;
	cout << boolalpha << ((int) a == (int &)a) << endl;

	float b = 0.0f;
	cout << (int )b << endl;
	cout << &b << endl;
	cout << (int &)b << endl;
	cout << boolalpha << ((int) b == (int &)b) << endl;

	return 0;
	
}

面试宝典之程序设计基本概念 随笔 第9张

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
	unsigned char a = 0xA5;
	unsigned char b = ~a >> 4 + 1;

	cout << b << endl;

	printf("%d\n", b);

	return 0;
}

面试宝典之程序设计基本概念 随笔 第10张

注意:

cout << b << endl;


输出的为不可见字符。

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄