当前位置:网站首页>Classic questions about data storage

Classic questions about data storage

2022-07-07 05:51:00 It's Yi'an

1. Ask about the output

#include<stdio.h>
#include<windows.h>
int main(void) {
	
	unsigned int b = 5;
	for (b = 9; b >= 0; b--) {
		printf("%u\n", b);
		Sleep(500);
	}
	return 0;
}

Notice here that b It's unsigned , Its value has been 0-->2^32-1 Between the circulation , The program will enter an infinite loop after running .

2. Ask about the output

#include<stdio.h>
#include<string.h>
int main(void) {
	char a[1000];
	int i = 0;
	for (i = 0; i < 1000; i++) {
		a[i] = -1 - i;
	}
	printf("%d\n", strlen(a));

	return 0;
}

Here is a question of scope ,char The signed range of types is -128-->127,strlen The function is looking for in the string '\0', Find one i, When it is put into char In Chinese, it means -1 when , The result is 0,, Its value is 255.

原网站

版权声明
本文为[It's Yi'an]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130732431827.html