Understanding Pointers

本文介绍了C语言中指针的基本概念,包括指针类型、创建与引用方式、与数组的关系及如何指向函数等内容。通过实例说明了不同类型的指针转换、函数指针声明等高级用法。
Pointers are a central feature of the C Programming language. They server as a uniform way to generate references to elements within different data structures. Pointers are a source of confusion for novice programmers, but the underlying concepts are fairly simple.

1.Every pointer has an associated type.
2.Every pointer has a value.
3.Pointers are created with the & operator.
4.Pointers are dereferenced with the * operator.
5.Arrays and pointers are closely related.
6.Casting from one type of pointer to another changes is type but not its value.
If p is a pointer of type char * having value q, then the expression (int *)p + 7 computes q + 28, while (int *)(p + 7) computes q +7.
7.Pointers can also point to function.
The value of a function pointer is the address of the first instruction in the machine-code representation of the function.

Example:
int (*f)(int *);
Thus we see that f is a pointer, as indicated by"(*f)". It is a pointer to a function that has a single int * as an argument, as indicated by "(*f)(int *)".Finally, we see that it is a pointer to a function that takes an int * as an argument and returns int.

int *f(int *);
would be read as:
(int *)  f(int *);
That is, it would be interpreted as a function prototype, declaring a function f that has an int * as its argument and returns an int *.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值