华为最爱考的笔试题

目录:

  • 整型存储练习
    • 1.练习一:如下程序输出a,b,c分别是多少
      • a.分析
      • b.运行结果
    • 2.练习二:下面程序输出什么?
      • a.分析
      • b.运行结果
    • 3.练习三:下面代码输出结果是什么?
      • a.分析
      • b.运行结果
    • 4.练习四:下面代码输出结果是什么?
      • a.分析
      • b.运行结果
    • 5.练习五:下面代码输出结果是什么?
      • a.分析
      • b.运行结果

整型存储练习

1.练习一:如下程序输出a,b,c分别是多少

#include 
int main()
{
     
    char a= -1;
    signed char b=-1;
    unsigned char c=-1;
    printf("a=%d,b=%d,c=%d",a,b,c);
    return 0; 
    }

a.分析

华为最爱考的笔试题_第1张图片

b.运行结果

华为最爱考的笔试题_第2张图片

2.练习二:下面程序输出什么?

#include 
int main()
{
     
    char a = -128;
    printf("%u\n",a);
    return 0; 
 }

a.分析

注:无符号原反补是一样的
华为最爱考的笔试题_第3张图片

b.运行结果

华为最爱考的笔试题_第4张图片

3.练习三:下面代码输出结果是什么?

#include 
int main()
{
     
    char a = 128;
    printf("%u\n",a);
    return 0; 
 }

a.分析

华为最爱考的笔试题_第5张图片

b.运行结果

华为最爱考的笔试题_第6张图片

4.练习四:下面代码输出结果是什么?

#include 
int main()
{
     
	int i = -20;
	unsigned int j = 10;
	printf("%d\n", i+j);
	return 0;
}

a.分析

注:有符号遇到无符号向范围大的转化
华为最爱考的笔试题_第7张图片

b.运行结果

华为最爱考的笔试题_第8张图片

5.练习五:下面代码输出结果是什么?

#include 
int main()
{
     
	unsigned char a = 200;
	unsigned char b = 100;
	unsigned char c = 0;
	c = a + b;
	printf("%d %d", a + b, c);
	return 0;
}

a.分析

printf在传入参数的时候如果是整形会默认传入四字节,所以a+b的结果是用一个四字节的整数接收的,不会越界。而c已经在c = a + b这一步中丢弃了最高位的1
华为最爱考的笔试题_第9张图片

b.运行结果

华为最爱考的笔试题_第10张图片

你可能感兴趣的:(C语言,c语言,整型存储,华为)