15.md 1.6 KB
Newer Older
W
wizardforcel 已提交
1
# C 程序:查找`int`,`float`,`double`和`char`的大小
W
wizardforcel 已提交
2 3 4

> 原文: [https://beginnersbook.com/2017/09/c-program-to-find-the-size-of-int-float-double-andchar_](https://beginnersbook.com/2017/09/c-program-to-find-the-size-of-int-float-double-and-char/)

W
wizardforcel 已提交
5
该程序查找数据类型的大小,如`char``int``float``double`
W
wizardforcel 已提交
6 7 8

## 示例:用于在 C 中查找数据类型大小的程序

W
wizardforcel 已提交
9
在这个程序中,我们使用`sizeof()`运算符来查找数据类型的大小。当`sizeof` 与原始数据类型(如`int``float``double``char`)一起使用时,它将返回分配给它们的内存量。
W
wizardforcel 已提交
10

W
wizardforcel 已提交
11
```c
W
wizardforcel 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24
#include<stdio.h>
int main()
{
    printf("Size of char: %ld byte\n",sizeof(char));
    printf("Size of int: %ld bytes\n",sizeof(int));
    printf("Size of float: %ld bytes\n",sizeof(float));
    printf("Size of double: %ld bytes", sizeof(double));
    return 0;
}
```

输出:

W
wizardforcel 已提交
25
```c
W
wizardforcel 已提交
26 27 28 29 30 31 32 33
Size of char: 1 byte
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
```

看看这些相关的 C 程序:

W
wizardforcel 已提交
34
1.  [C 程序:相加两个数字](https://beginnersbook.com/2017/09/c-program-to-add-two-numbers/)
W
wizardforcel 已提交
35 36 37
2.  [C 程序:查找数组中的元素数](https://beginnersbook.com/2017/09/c-program-to-find-the-number-of-elements-in-an-array/)
3.  [C 程序:检查数字是正数还是负数](https://beginnersbook.com/2015/02/c-program-to-check-whether-the-given-integer-is-positive-or-negative/)
4.  [C 程序:按升序排列数字](https://beginnersbook.com/2015/02/c-program-to-arrange-numbers-in-ascending-order/)
W
wizardforcel 已提交
38
5.  [C 程序:查找商和余数](https://beginnersbook.com/2017/09/c-program-to-find-quotient-and-remainder/)