Reg:指针 [英] Reg : Pointers

查看:60
本文介绍了Reg:指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我一些指示,


什么是指针?

如何在C编程中使用指针?

他们是如何工作的?


i经历了一本书,我有点困惑。


问候,

Satish ......

Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

i had gone through one book, i am a bit confused.

Regards,
Satish...

推荐答案

" Satish Kumar" < SK ******** @ gmail.com>在消息中写道

news:69 ************************** @ posting.google.c om ...
"Satish Kumar" <sk********@gmail.com> wrote in message
news:69**************************@posting.google.c om...
任何人都可以给我一些指示,

指针是什么?
如何在C编程中使用指针?
它们如何工作?

我读了一本书,我有点困惑。
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

I had gone through one book, i am a bit confused.




我*做*有一个指针给你:


Google


使用短语:


指针C教程


干杯,


Anthony Borla



I *do* have a pointer for you:

Google

using the phrase:

Pointers C Tutorial

Cheers,

Anthony Borla


Satish Kumar< sk ******** @ gmail.com> ;写道:
Satish Kumar <sk********@gmail.com> wrote:
任何人都可以给我一些关于,
什么是指针?


指针是可以保存地址的变量。通常情况下,他们会为
分配一个值,该值是另一个对象的地址(正常的
变量,一个函数或另一个指针)。一旦发生这种情况

你可以通过解除引用来访问指针指向的内容,

这是通过将(一元)'''''运算符放在前面来完成的

指针变量名称。


所以当你有例如


int i = 5;

int * ip =& i; / *指针,指向i * /


然后您可以例如做


printf(我是%d \ n,* ip);




* ip = 7; / *通过指针间接改变我* /


printf(我现在是%d \ n,i)


这将打印出来


i现在是7

如何在C编程中使用指针?


首先,它们允许您将变量地址传递给

函数,这样就可以更改内容
从函数中指向变量的
(记住:在C变量中
按值传递,所以函数只接收参数值的
变量并且不能改变变量

本身。


其次,指针是必不可少的,当你需要金额
记忆你只能在程序已经运行时确定。像malloc()这样的函数会返回一个指向

内存缓冲区的指针,其大小可以告诉函数。如果

函数成功,你可以使用返回值来访问那个内存,例如


int * a = malloc( 100 * sizeof * int);

if(a!= NULL){

a [17] = 42;

free(a);

}


但是指针和列表还有数以百计的其他用途

只有立即想到的小子集才会出现

这个帖子太长了。没有指针的C将是一个相当无用的语言。

它们如何工作?


你是什么意思工作?

i经历了一本书,我有点困惑。
Can any one give me indetail about, what are pointers?
Pointers are variables that can hold addresses. Normally, they get
assigned a value that is the address of another object (a normal
variable, a function or another pointer). Once that has happened
you can access what the pointer points to by dereferencing it,
which is done by putting the (unary) ''*'' operator in front of
the pointer variables name.

So when you have e.g.

int i = 5;
int *ip = &i; /* pointer, pointing to i */

then you can e.g. do

printf( "i is %d\n", *ip );

or

*ip = 7; /* change i indirectly via the pointer */

printf( "i is now %d\n", i )

and this will print out

i is now 7
How are pointers useful in C prgramming?
First of all, they allow you to pass addresses of variables to
functions, and by doing so it is possible to change the content
of the variable pointed to from within the function (remember:
in C variables are passed by value, so a function only receives
the value of an argument variable and can''t change the variable
itself).

Second, pointers are indispensable when you need amounts of
memory you can only determine while the program is already
running. Functions like malloc() return you a pointer to a
memory buffer with a size you can tell the function. If the
function succeeds you can use the returned value to access
that memory, e.g.

int *a = malloc( 100 * sizeof *int );
if ( a != NULL ) {
a[ 17 ] = 42;
free( a );
}

But there are hundreds of other uses of pointers and listing
only the small subset which immediately comes to mind would
make this posting much too long. C without pointers would be
a rather useless language.
How do they work?
What do you mean by "work"?
i had gone through one book, i am a bit confused.




我们都是这样开始的(或多或少)。继续阅读和体验/ b
menting,你很快就能理解;-)试图绘制

一些代表指针和变​​量的框和箭头de /

picting他们之间的关系有时会有所帮助(特别是

,如果你开始玩指针指针)。


问候,Jens

-

\ Jens Thoms Toerring ___ Je * **********@physik.fu-berlin.de

\ __________________________ http://www.toerring.de





Satish Kumar写道:


Satish Kumar wrote:
任何人都可以给我一些指示,

指针是什么?
指针如何在C编程中有用?
他们如何工作?

我读了一本书,我有点困惑。

问候,
Satish ......
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

i had gone through one book, i am a bit confused.

Regards,
Satish...




C-FAQ @ Section 4.

http://www.eskimo.com/~scs/C-faq/top.html

对指针有很好的理解/>
一切都好:)


- 拉维



C-FAQ @ Section 4.

http://www.eskimo.com/~scs/C-faq/top.html

gives a good understanding on Pointers
All the best :)

- Ravi


这篇关于Reg:指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆