博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一本介绍C指针的书--指针是什么1.1
阅读量:6319 次
发布时间:2019-06-22

本文共 2629 字,大约阅读时间需要 8 分钟。

hot3.png

    One of those things beginners in C find difficult is the concept of pointers. The purpose

of this tutorial is to provide an introduction to pointers and their use to these beginners.  

I have found that often the main reason beginners have a problem with pointers is that

they have a weak or minimal feeling for variables, (as they are used in C). Thus we start

with a discussion of C variables in general.  

A variable in a program is something with a name, the value of which can vary. The way

the compiler and linker handles this is that it assigns a specific block of memory within

the computer to hold the value of that variable. The size of that block depends on the

range over which the variable is allowed to vary. For example, on PC's the size of an

integer variable is 2 bytes, and that of a long integer is 4 bytes. In C the size of a variable

type such as an integer need not be the same on all types of machines.  

When we declare a variable we inform the compiler of two things, the name of the

variable and the type of the variable. For example, we declare a variable of type integer

with the name k by writing:  

    int k;  

On seeing the "int" part of this statement the compiler sets aside 2 bytes of memory (on a

PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the

symbol k and the relative address in memory where those 2 bytes were set aside.  

Thus, later if we write:  

    k = 2;  

we expect that, at run time when this statement is executed, the value 2 will be placed in

that memory location reserved for the storage of the value of k. In C we refer to a

variable such as the integer k as an "object".  

In a sense there are two "values" associated with the object k. One is the value of the

integer stored there (2 in the above example) and the other the "value" of the memory

location, i.e., the address of k. Some texts refer to these two values with the nomenclature

rvalue (right value, pronounced "are value") and lvalue (left value, pronounced "el

value") respectively.  

In some languages, the lvalue is the value permitted on the left side of the assignment

operator '=' (i.e. the address where the result of evaluation of the right side ends up). The

rvalue is that which is on the right side of the assignment statement, the 2 above. Rvalues

cannot be used on the left side of the assignment statement. Thus: 2 = k; is illegal.

Actually, the above definition of "lvalue" is somewhat modified for C. According to

K&R II (page 197): [1] 

"An object is a named region of storage; an lvalue is an expression

referring to an object." 

转载于:https://my.oschina.net/clearchen/blog/70810

你可能感兴趣的文章
云服务正在吞噬世界!
查看>>
高性能 Lua 技巧(译)
查看>>
区分指针、变量名、指针所指向的内存
查看>>
最近话题火爆的四件事你知道不?
查看>>
SpringBoot整合MyBatis
查看>>
Android 类库书签更新(一)
查看>>
Unity3D Input按键系统
查看>>
简单的一条SQL,不简单的做事思维 NOT IN 、NOT EXISTS、LEFT JOIN用法差别 ...
查看>>
DataWorks:任务未运行自助排查
查看>>
ionic/cordova热部署
查看>>
「镁客早报」特斯拉裁员,马斯克解释没有办法;微软推出Azure DevOps赏金计划...
查看>>
centos 7.4 使用 pgxc_ctl 安装与使用
查看>>
Redis 单key值过大 优化方式
查看>>
【数据库】表分区
查看>>
nutz-sqltpl 1.3.4.RELEASE 发布,在 Nutz 项目中“解决 Java 拼接 SQL”问题
查看>>
城市 | 800个地铁站数据透析的京沪白领图鉴:隐形土豪、无产中产阶级和猪猪女孩...
查看>>
前端脚本!网站图片素材中文转英文
查看>>
linux的常用易忘命令
查看>>
PHP 分割字符串
查看>>
java 基于QRCode、zxing 的二维码生成与解析
查看>>