c语言声明变量和定义变量_C变量和定义

c语言声明变量和定义变量

c语言声明变量和定义变量

[rps-include post=6557]

[rps-include post = 6557]

Most important function is storing data while the application running. The data may be  age, username, picture, full name etc. To hold data variables are used. Variables are stored in the memory. After application run all variables are cleaned. So variables do not persists between application runs. As variables stored in memory they need some space in the memory but how much? This memory size can change according to data type or variable type.We will look variable types below. Say we have a string like “Hello poftut” and as number 1 . They will occupy different lengths of memory. Knowing this is enough for now.

最重要的功能是在应用程序运行时存储数据。 数据可以是年龄,用户名,图片,全名等。使用保留数据变量。 变量存储在内存中。 应用程序运行后,将清除所有变量。 因此,变量不会在应用程序运行之间持续存在。 作为存储在内存中的变量,它们需要一些内存空间,但是需要多少空间? 该内存大小可以根据数据类型或变量类型而变化。我们将在下面查找变量类型。 假设我们有一个像“ Hello poftut”这样的字符串,并且是数字1 。 它们将占用不同的内存长度。 现在知道这一点就足够了。

句法 (Syntax)

We have already seen syntax of C programming language but look again will make learning better. Below is a syntax which is the same with statement to define a variable.

我们已经看过C编程语言的语法,但是再看一下会使学习更好。 以下是与用于定义变量的语句相同的语法。

type variable_name;

Here type is the type of variable as we stated before. Because there are different type of data like number, string, floating-point etc. Types are differentiated to make C programming language more efficient and fast. If all data were same type there will be a lot of casting or type guessing  to operate on them.

在这里type 是我们之前所说的变量类型。 因为存在不同类型的数据,例如数字,字符串,浮点数等。对类型进行区分以使C编程语言更加高效和快速。 如果所有数据都是同一类型,那么将需要进行大量转换或类型猜测。

Here we will define a variable that holds age.

在这里,我们将定义一个保存年龄的变量。

int age;

int is our variable type and age is our variable or variable name which will hold the age data.

int 是我们的变量类型和age 是我们的变量或变量名称,将保存年龄数据。

设定值 (Set Value)

Just defining a variable is not enough because we want to hold data on variable. Here is how can we do this

仅定义变量是不够的,因为我们要保留变量上的数据。 这是我们该怎么做

int age=25;

In this line there is two step. One step is defining an int variable named age . Second is assigning 25 to the this variable named age .

在这一行中有两个步骤。 第一步是定义一个int 变量age 。 其次是分配25 到这个名为age变量 

An other way to set value is after definition. So we learned that we have no obligation to set data on the variable definition.

设置值的另一种方法是在定义之后。 因此,我们了解到我们没有义务在变量定义上设置数据。

int age;

age=25;

定义多个变量 (Define Multiple Variables)

We can define multiple variables in a single shot to make it easy and readable like below. This is called as multiple variable definition with single statement.

我们可以在一个镜头中定义多个变量,以使其变得简单易读,如下所示。 这称为带有单个语句的多变量定义。

int age,year,length;

All of these variables named ageyear, length are integer type are defined in a single statement. We will look variable type next chapters.

所有这些名为ageyearlength都是整数类型的变量都在单个语句中定义。 我们将在下一章中介绍变量类型。

LEARN MORE  Memcached Set Operation with Python Example
通过Python示例了解更多Memcached设置操作

定义和分配多个变量(Define and Assign Multiple Variables)

Now we merge what we have learned and define multiple variables in a single line by setting values to them.

现在,我们合并所学内容,并通过为它们设置值来在一行中定义多个变量。

int age=25, year=2016, length=180;

[rps-include post=6557]

[rps-include post = 6557]

翻译自: https://www.poftut.com/c-variables-definition/

c语言声明变量和定义变量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值