47 lines
1.4 KiB
Markdown
47 lines
1.4 KiB
Markdown
|
---
|
||
|
title: 第一次作业(答案)
|
||
|
date: 2020-10-30 09:53:13
|
||
|
tags:
|
||
|
---
|
||
|
|
||
|
|
||
|
# 第一题
|
||
|
|
||
|
写出下列程序运行的结果:
|
||
|
|
||
|
```
|
||
|
sizeof: 4, a = 61, b = 62
|
||
|
sizeof: 1, c1 = a, c2 = b
|
||
|
sizeof: 4, d = 3.56 , e = -6.78
|
||
|
sizeof: 8, f = 3157.890121 , g = 0.123456789000
|
||
|
sizeof: 4, m = 50000, n = -60000
|
||
|
sizeof: 4, p = 32768, q = 4000
|
||
|
```
|
||
|
|
||
|
有些同学可能遇到警告:`"printf": 格式字符串"%d"需要类型"int"的参数,但可变参数 1 拥有了类型"size_t"`,这是因为`sizeof()`的类型是`size_t`而非`int`,在`printf()`中与`%d`的类型不匹配。可以尝试`%zu`(C99标准及以后)或`%lu`(ANSI C标准)。
|
||
|
|
||
|
# 第二题
|
||
|
|
||
|
```
|
||
|
9, 11, 9, 10
|
||
|
```
|
||
|
|
||
|
# 第三题
|
||
|
|
||
|
| # | 表达式 | 变量的值 | 结果 |
|
||
|
| :---: | :------------------------------------- | :--------------------------------- | :---- |
|
||
|
| 1 | `3.5 + 1 / 2 + 56 % 10` | | `9.5` |
|
||
|
| 2 | `(a++ * 1 / 3)` | 设`a = 2` | `0` |
|
||
|
| 3 | `x + a % 3 * (int)(x + y) % 2 / 4` | 设`x = 2.5, a = 7, y = 4.7` | `2.5` |
|
||
|
| 4 | `(float)(a + b) / 2 + (int)x % (int)y` | 设a` = 2, b = 3, x = 3.5, y = 2.5` | `3.5` |
|
||
|
| 5 | `x = (x = ++y, x + 5, x / 5)` | 设`x = 3, y = 4` | `1` |
|
||
|
|
||
|
# 第五题
|
||
|
|
||
|
写出下面表达式运算后a的值,设原来a = 12。
|
||
|
|
||
|
1. `24`
|
||
|
2. `60`
|
||
|
3. `0`
|
||
|
4. `0`
|