c语言中浮点数和整数转换_C中的数据类型-整数,浮点数和空隙说明
c语言中浮点数和整数转换
C中的数据类型 (Data Types in C)
There are several different ways to store data in C, and they are all unique from each other. The types of data that information can be stored as are called data types. C is much less forgiving about data types than other languages. As a result, it’s important to make sure that you understand the existing data types, their abilities, and their limitations.
有几种不同的方法可以将数据存储在C中,并且它们彼此之间是唯一的。 可以存储信息的数据类型称为数据类型。 与其他语言相比,C对于数据类型的宽容程度要低得多。 因此,重要的是要确保您了解现有的数据类型,它们的功能及其局限性。
One quirk of C’s data types is that they depend entirely on the hardware that you’re running your code on. An int
on your laptop will be smaller than an int
on a supercomputer, so knowing the limitations of the hardware you’re working on is important. This is also why the data types are defined as being minimums- an int
value, as you will learn, is at minimum -32767 to 32767: on certain machines, it will be able to store even more values that this.
C的数据类型的一个怪癖是它们完全取决于您在其上运行代码的硬件。 笔记本电脑上的int
会比超级计算机上的int
小,因此了解所用硬件的局限性很重要。 这也是为什么将数据类型定义为最小值的原因-正如您将学到的那样,一个int
值至少为-32767到32767:在某些机器上,它将能够存储更多的值。
There are two categories that we can break this into: integers, and floating point numbers. Integers are whole numbers. They can be positive, negative, or zero. Numbers like -321, 497, 19345, and -976812 are all perfectly valid integers, but 4.5 is not because 4.5 is not a whole number.
我们可以将其分为两类:整数和浮点数。 整数是整数。 它们可以是正数,负数或零。 像-321、497、19345和-976812之类的数字都是完全有效的整数,但是4.5并不是因为4.5不是整数。
Floating point numbers are numbers with a decimal. Like integers, -321, 497, 19345, and -976812 are all valid, but now 4.5, 0.0004, -324.984, and other non-whole numbers are valid too.
浮点数是带小数的数字。 像整数一样,-321、497、19345和-976812都有效,但是现在4.5、0.0004,-324.984和其他非整数也都有效。
C allows us to choose between several different options with our data types because they are all stored in different ways on the computer. As a result, it is important to be aware of the abilities and limitations of each data type to choose the most appropriate one.
C允许我们在数据类型的几个不同选项之间进行选择,因为它们都以不同的方式存储在计算机上。 因此,重要的是要知道每种数据类型选择最合适的能力和局限性。
整数数据类型 (Integer data types)
字符: char
(Characters: char
)
char
holds characters- things like letters, punctuation, and spaces. In a computer, characters are stored as numbers, so char
holds integer values that represent characters. The actual translation is described by the ASCII standard. Here’s a handy table for looking up that.
char
包含字符,例如字母,标点和空格。 在计算机中,字符存储为数字,因此char
保留代表字符的整数值。 实际翻译由ASCII标准描述。 这是一个方便查找的桌子。
The actual size, like all other data types in C, depends on the hardware you’re working on. By minimum, it is at least 8 bits, so you will have at least 0 to 127. Alternatively, you can use signed char
to get at least -128 to 127.
像C中的所有其他数据类型一样,实际大小取决于您正在使用的硬件。 至少,它至少是8位,因此您至少要有0到127。或者,您可以使用带signed char
来获得至少-128到127。
标准整数: int
(Standard Integers: int
)
The amount of memory that a single int
takes depends on the hardware. However, you can expect an int
to be at least 16 bits in size. This means that it can store values from -32,768 to 32,767, or more depending on hardware.
一个int
占用的内存量取决于硬件。 但是,您可以预期int
大小至少为16位。 这意味着它可以存储-32,768到32,767或更多的值,具体取决于硬件。
Like all of these other data types, there is an unsigned
variant that can be used. The unsigned int
can be positive and zero but not negative, so it can store values from 0 to 65,535, or more depending on hardware.
像所有其他所有数据类型一样,可以使用unsigned
变体。 unsigned int
可以是正数,可以是零,但不能为负数,因此它可以存储0到65,535之间的值,或者取决于硬件而更多。
短整数: short
(Short integers: short
)
This doesn’t get used often, but it’s good to know that it exists. Like int, it can store -32768 to 32767. Unlike int, however, this is the extent of its ability. Anywhere you can use short
, you can use int
.
这并不经常使用,但是很高兴知道它的存在。 与int一样,它可以存储-32768到32767。但是,与int不同,这是其功能的程度。 只要可以使用short
,就可以使用int
。
长整数: long
(Longer integers: long
)
The long
data type stores integers like int
, but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647. Alternatively, use unsigned long
for a range of 0 to 4,294,967,295.
long
数据类型存储整数,如int
,但以占用更多内存为代价,提供了更大范围的值。 Long存储至少32位,范围为-2,147,483,648至2,147,483,647。 或者,使用unsigned long
,范围为0到4,294,967,295。
甚至更长的整数: long long
(Even longer integers: long long
)
The long long
data type is overkill for just about every application, but C will let you use it anyway. It’s capable of storing at least −9,223,372,036,854,775,807 to 9,223,372,036,854,775,807. Alternatively, get even more overkill with unsigned long long
, which will give you at least 0 to 18,446,744,073,709,551,615.
long long
数据类型对于几乎每个应用程序来说都是多余的,但是C仍然可以让您使用它。 它能够存储至少-9,223,372,036,854,775,807至9,223,372,036,854,775,807。 或者,使用unsigned long long
获得更多的过大杀伤力,这将使您至少有0到18,446,744,073,709,551,615。
浮点数数据类型 (Floating point number data types)
基本浮点数: float
(Basic Floating point numbers: float
)
float
takes at least 32 bits to store, but gives us 6 decimal places from 1.2E-38 to 3.4E+38.
float
至少需要32位来存储,但是从1.2E-38到3.4E + 38,我们给了6个小数位。
双打: double
(Doubles: double
)
double
takes double the memory of float (so at least 64 bits). In return, double can provide 15 decimal place from 2.3E-308 to 1.7E+308.
double
占用float内存的两倍(因此至少需要64位)。 作为回报,double可以提供从2.3E-308到1.7E + 308的小数点后15位。
获得更大范围的双打: long double
(Getting a wider range of doubles: long double
)
long double
takes at least 80 bits. As a result, we can get 19 decimal places from 3.4E-4932 to 1.1E+4932.
long double
至少需要80位。 结果,我们可以从3.4E-4932到1.1E + 4932获得19位小数。
选择正确的数据类型 (Picking the right data type)
C makes pick the data type, and makes us be very specific and intentional about the way that we do this. This gives you a lot of power over your code, but it’s important to pick the right one.
C会选择数据类型,并使我们对执行此操作的方式非常明确和有目的地。 这为您提供了很多控制代码的能力,但是选择正确的代码很重要。
In general, you should pick the minimum for your task. If you know you’ll be counting from integer 1 to 10, you don’t need a long and you don’t need a double. If you know that you will never have negative values, look into using the unsigned
variants of the data types. By providing this functionality rather than doing it automatically, C is able to produce very light and efficient code. However, it’s up to you as the programmer to understand the abilities and limitations, and choose accordingly.
通常,您应该为任务选择最低要求。 如果您知道要从整数1到10进行计数,则不需要很长,也不需要加倍。 如果您知道永远不会有负值,请研究使用数据类型的unsigned
变体。 通过提供此功能而不是自动执行,C可以生成非常轻便且高效的代码。 但是,作为程序员,您需要了解功能和限制并做出相应选择。
We can use the sizeof() operator to check the size of a variable. See the following C program for the usage of the various data types:
我们可以使用sizeof()运算符来检查变量的大小。 有关各种数据类型的用法,请参见以下C程序:
#include <stdio.h>int main()
{int a = 1;char b ='G';double c = 3.14;printf("Hello World!\n");//printing the variables defined above along with their sizesprintf("Hello! I am a character. My value is %c and ""my size is %lu byte.\n", b,sizeof(char));//can use sizeof(b) above as wellprintf("Hello! I am an integer. My value is %d and ""my size is %lu bytes.\n", a,sizeof(int));//can use sizeof(a) above as wellprintf("Hello! I am a double floating point variable."" My value is %lf and my size is %lu bytes.\n",c,sizeof(double));//can use sizeof(c) above as wellprintf("Bye! See you soon. :)\n");return 0;
}
输出: (Output:)
Hello World!Hello! I am a character.
My value is G and my size is 1 byte.
Hello! I am an integer.
My value is 1 and my size is 4 bytes.
Hello! I am a double floating point variable.
My value is 3.140000 and my size is 8 bytes.
Bye! See you soon. :)
虚空类型 (The Void type)
The void type specifies that no value is available. It is used in three kinds of situations:
void类型指定没有可用值。 它在三种情况下使用:
1.函数返回空值 (1. Function returns as void)
There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. For example, void exit (int status);
C中有各种函数不返回任何值,或者可以说它们返回void。 没有返回值的函数的返回类型为void。 例如, void exit (int status);
2.函数参数为void (2. Function arguments as void)
There are various functions in C which do not accept any parameter. A function with no parameter can accept a void. For example, int rand(void);
C中有许多不接受任何参数的函数。 没有参数的函数可以接受空白。 例如, int rand(void);
3.指向无效的指针 (3. Pointers to void)
A pointer of type void * represents the address of an object, but not its type. For example, a memory allocation function void *malloc( size_t size);
returns a pointer to void which can be casted to any data type.
类型为void *的指针表示对象的地址,但不表示其类型。 例如,一个内存分配函数void *malloc( size_t size);
返回指向void的指针,该指针可以转换为任何数据类型。
翻译自: https://www.freecodecamp.org/news/data-types-in-c-integer-floating-point-and-void-explained/
c语言中浮点数和整数转换
相关文章:

【如何快速的开发一个完整的iOS直播app】(美颜篇)
前言在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播app(原理篇)开发一款直播app,美颜功能是很重要的,如果没有美颜功能,可能分分钟钟掉粉千万,本篇主要讲解直播中美颜…

Linux内核分析——第五章 系统调用
第五章 系统调用 5.1 与内核通信 1、系统调用在用户空间进程和硬件设备之间添加了一个中间层,该层主要作用有三个: (1)为用户空间提供了一种硬件的抽象接口 (2)系统调用保证了系统的稳定和安全 (…

BZOJ 3110
http://www.lydsy.com/JudgeOnline/problem.php?id3110 整体二分区间修改树状数组维护 #include<cstdio> #define FOR(i,s,t) for(register int is;i<t;i) inline int max(int a,int b){return a>b?a:b;} inline int min(int a,int b){return a<b?a:b;} type…

css 选择器 伪元素_CSS伪元素-解释选择器之前和之后
css 选择器 伪元素选择器之前 (Before Selector) The CSS ::before selector can be used to insert content before the content of the selected element or elements. It is used by attaching ::before to the element it is to be used on.CSS ::before选择器可用于在选定…

各种面试题啊1
技术 基础 1.为什么说Objective-C是一门动态的语言? 什么叫动态静态 静态、动态是相对的,这里动态语言指的是不需要在编译时确定所有的东西,在运行时还可以动态的添加变量、方法和类 Objective-C 可以通过Runtime 这个运行时机制,…

PEP8 Python
写在前面 对于代码而言,相比于写,它更多是读的。 pep8 一、代码编排 缩进,4个空格的缩进,编辑器都可以完成此功能;每行最大长度79,换行可以使用反斜杠,换行点要在操作符的后边。类和top-level函…

粒子滤波 应用_如何使用NativeScript开发粒子物联网应用
粒子滤波 应用If youre developing any type of IoT product, inevitably youll need some type of mobile app. While there are easy ways, theyre not for production use.如果您要开发任何类型的物联网产品,则不可避免地需要某种类型的移动应用程序。 尽管有简单…

wkwebView基本使用方法
WKWebView有两个delegate,WKUIDelegate 和 WKNavigationDelegate。WKNavigationDelegate主要处理一些跳转、加载处理操作,WKUIDelegate主要处理JS脚本,确认框,警告框等。因此WKNavigationDelegate更加常用。 比较常用的方法: #p…

引用类型(一):Object类型
对象表示方式 1、第一种方式:使用new操作符后跟Object构造函数 var person new Object();<br/> person.name Nicholas;<br/> person.age 29; 2、对象字面量表示法 var person {name:Nicholas,age:29 } *:在age属性的值29的后面不能添加逗号…

(第四周)要开工了
忙碌的一周又过去了,这周的时间很紧,但是把时间分配的比较均匀,考研复习和各门功课都投入了一定的精力,所以不像前三周一样把大多数时间都花费在了软件工程上。也因为结对项目刚开始,我们刚刚进行任务分工以及查找资料…

统计数字,空白符,制表符_为什么您应该在HTML中使用制表符空间而不是多个非空白空间(nbsp)...
统计数字,空白符,制表符There are a number of ways to insert spaces in HTML. The easiest way is by simply adding spaces or multiple character entities before and after the target text. Of course, that isnt the DRYest method.有多种方法可以在HTML中插入空格。…

Python20-Day02
1、数据 数据为什么要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同类型的数据表示; 数据类型 数字(整形,长整形,浮点型,复数),字符串,列表,元组…

Android网络框架-OkHttp3.0总结
一、概述 OkHttp是Square公司开发的一款服务于android的一个网络框架,主要包含: 一般的get请求一般的post请求基于Http的文件上传文件下载加载图片支持请求回调,直接返回对象、对象集合支持session的保持github地址:https://githu…

第一天写,希望能坚持下去。
该想的都想完了,不该想的似乎也已经尘埃落定了。有些事情,终究不是靠努力或者不努力获得的。顺其自然才是正理。 以前很多次想过要努力,学习一些东西,总是不能成,原因很多: 1.心中烦恼,不想学…

mac gource_如何使用Gource显示项目的时间表
mac gourceThe first time I heard about Gource was in 2013. At the time I watched this cool video showing Ruby on Rails source code evolution:我第一次听说Gource是在2013年 。 当时,我观看了这段很酷的视频,展示了Ruby on Rails源代码的演变&a…

insert语句让我学会的两个MySQL函数
我们要保存数据到数据库,插入数据是必须的,但是在业务中可能会出于某种业务要求,要在数据库中设计唯一索引;这时如果不小心插入一条业务上已经存在同样key的数据时,就会出现异常。 大部分的需求要求我们出现唯一键冲突…

对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。...
C#引入外部非托管类库时,有时候会出现“对PInvoke函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配”的报错。 通常在DllImport标签内加入属性CallingConventionCallingConvention.Cdecl即可解决该问题。 如: [Dll…

Python字符串方法用示例解释
字符串查找方法 (String Find Method) There are two options for finding a substring within a string in Python, find() and rfind().在Python中的字符串中有两个选项可以找到子字符串: find()和rfind() 。 Each will return the position that the substring …

关于命名空间namespace
虽然任意合法的PHP代码都可以包含在命名空间中,但只有以下类型的代码受命名空间的影响,它们是:类(包括抽象类和traits)、接口、函数和常量。在声明命名空间之前唯一合法的代码是用于定义源文件编码方式的 declare 语句…

一 梳理 从 HDFS 到 MR。
MapReduce 不仅仅是一个工具,更是一个框架。我们必须拿问题解决方案去适配框架的 map 和 reduce 过程很多情况下,需要关注 MapReduce 作业所需要的系统资源,尤其是集群内部网络资源的使用情况。这是MapReduce 框架在设计上的取舍,…

huffman树和huffman编码
不知道为什么,我写的代码都是又臭又长。 直接上代码: #include <iostream> #include <cstdarg> using namespace std; class Node{ public:int weight;int parent, lChildren, rChildren;Node(int weight, int parent, int lChildren, int …

react 监听组合键_投资组合中需要的5个React项目
react 监听组合键Youve put in the work and now you have a solid understanding of the React library.您已经完成工作,现在对React库有了扎实的了解。 On top of that, you have a good grasp of JavaScript and are putting its most helpful features to use …

Unity 单元测试(PLUnitTest工具)
代码测试的由来 上几个星期上面分配给我一个装备系统,我经过了几个星期的战斗写完90%的代码. 后来策划告诉我需求有一定的改动,我就随着策划的意思修改了代码. 但是测试(Xu)告诉我装备系统很多功能都用不上了. Xu: 我有300多项测试用例,现在有很多项都无法运行了. 你修改了部分…

Best Time to Buy and Sell Stock II
题目: Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multipl…

求给定集合的幂集
数据结构中说这个问题可以用类似8皇后的状态树解法。 把求解过程看成是一棵二叉树,空集作为root,然后遍历给定集合中的元素,左子树表示取该元素,右子树表示舍该元素。 然后,root的左右元素分别重复上述过程。 就形成…

angular 命令行项目_Angular命令行界面介绍
angular 命令行项目Angular is closely associated with its command-line interface (CLI). The CLI streamlines generation of the Angular file system. It deals with most of the configuration behind the scenes so developers can start coding. The CLI also has a l…
oracle-imp导入小错filesize设置
***********************************************声明*********************************************************************** 原创作品,出自 “深蓝的blog” 博客。欢迎转载,转载时请务必注明出处。否则追究版权法律责任。表述有错误之处…

CentOS 7 下用 firewall-cmd / iptables 实现 NAT 转发供内网服务器联网
自从用 HAProxy 对服务器做了负载均衡以后,感觉后端服务器真的没必要再配置并占用公网IP资源。 而且由于托管服务器的公网 IP 资源是固定的,想上 Keepalived 的话,需要挤出来 3 个公网 IP 使用,所以更加坚定了让负载均衡后端服务器…

八皇后的一个回溯递归解法
解法来自严蔚敏的数据结构与算法。 代码如下: #include <iostream> using namespace std; const int N 8;//皇后数 int count 0;//解法统计 int a[N][N];//储存值的数组const char *YES "■"; const char *NO "□"; //const char *Y…