Pointer:  A pointer is a variable that contains the address of a variable.

if c is a char and p is a pointer that points to it, we could represent the situation this way:

&:The unary operator & gives the address of an object, so the statement

p = &c;

assigns the address of c to the varible p, and p is said to "point to " c.The & operator only applies to objects in memory:

array vs pointer

In C, there is a strong relationship between pointers and arrays, strong enough that pointers and arrays should be discussed simultaneously. Any operation that can be achieved by array subscripting can also be done with pointers. The pointer version will in general be faster but, at least to the uninitiated, somewhat harder to understand.

The correspondence between indexing and pointer arithmetic is very close. By definition, the value of a variable or expression of type array is the address of element zero  of the array. Thus after the assignment 
                                      pa = &a[0];
 pa and a have identical values. Since the name of an array is a synonym for the location of the initial element, the assignment pa=&a[0]can also be written as 
                                        pa = a;

Rather more surprising, at first sight, is the fact that a reference to a[i]can also be written as *(a+i). In evaluating a[i], C converts it to *(a+i)immediately; the two forms are equivalent. Applying the operator &to both parts of this equivalence, it follows that &a[i] and a+i are also identical: a+i is the address of the i-th element beyond a. As the other side of this coin, if pais a pointer, expressions might use it with a subscript; pa[i]is identical to *(pa+i). In short, an array-and-index expression is equivalent to one written as a pointer and offset. 
        There is one difference between an array name and a pointer that must be kept in mind. A pointer is a variable, so pa=a and pa++ are legal. But an array name is not a variable; constructions like a=pa and a++ are illegal.

Pointers and integers are not interchangeable.Zero is the sole exception: the constant zero may be assigned to a pointer, and a pointer may be compared with the constant zero. The symbolic constant NULL is often used in place of zero, as a mnemonic to indicate more clearly that this is a special value for a pointer.NULL is defined in <stdio.h>. We will use NULL henceforth.

Command-line Arguments

In environments that supports C, there is a way to pass command-line arguments or parameters to a program when it begins executing. When main is called, it is called with two aguments. The first(conventionally called argc,  for argument count) is the number of command-line arguments the program was invoked with; the second(argv, for argument vector) is a pointer to an array of character strings that contain the arguments, one per string.We customarily use multiple levels of pointers to manipulate

these character strings.

The simplest illustration is the program echo, which echoes its command-line arguments on a
single line, separated by blanks. That is, the command

echo hello, world
prints the output
                          hello, world 
               By convention, argv[0] is the name by which the program was invoked, so argc is at least 1. If argc is 1, there are no command-line arguments after the program name. In the example above, argc is 3, and argv[0], argv[1], and argv[2] are "echo", "hello,", and "world" respectively. The first optional argument is argv[1] and the last is argv[argc-1]; additionally, the standard requires that argv[argc] be a null pointer.

c pointer and array的更多相关文章

  1. Go: using a pointer to array

    下面的不是指针指向数组,而是指针指向Slice I'm having a little play with google's Go language, and I've run into someth ...

  2. C lang:Pointer and Array

    Xx_Introduction Point and Array germane. Xx_Code #include<stdio.h> #define SIZE 4 int main(voi ...

  3. The correct way to initialize a dynamic pointer to a multidimensional array

    From:https://stackoverflow.com/questions/18273370/the-correct-way-to-initialize-a-dynamic-pointer-to ...

  4. initial pointer [expert c]

    initial differece between pointer and array Both arrays and pointers can be initialized with a liter ...

  5. extension Array where Element 代码学习

    var fieldNames: [String] { let p = UnsafePointer<Int32>(self.pointer) return Array(utf8Strings ...

  6. 【译】Rust中的array、vector和slice

    原文链接:https://hashrust.com/blog/arrays-vectors-and-slices-in-rust/ 原文标题:Arrays, vectors and slices in ...

  7. CSharpGL(36)通用的非托管数组排序方法

    CSharpGL(36)通用的非托管数组排序方法 如果OpenGL要渲染半透明物体,一个方法是根据顶点到窗口的距离排序,按照从远到近的顺序依次渲染.所以本篇介绍对 UnmanagedArray< ...

  8. MMORPG大型游戏设计与开发(服务器 游戏场景 事件)

    今天第星期天,知识是永远是学习不完的,所以今天这部分算比较轻松,同时也希望大家会有一个好的周末.场景事件即场景的回调,和别的事件一样是在特定的条件下产生的,前面也介绍过场景的各种事件,今天详细的说一说 ...

  9. 《征服 C 指针》摘录6:解读 C 的声明

    一.混乱的声明——如何自然地理解 C 的声明? 通常,C 的声明 int hoge; 这样,使用“类型 变量名;”的形式进行书写. 可是,像“指向 int 的指针”类型的变量,却要像下面这样进行声明: ...

随机推荐

  1. cocos2d-x笔记2: 编译到安卓的步骤与注意事项

    博客地址: www.cnblogs.com/wolfred7464/ 不得不说,真心复杂,本篇博客总结的基本是最简最直接的步骤了,不用Cygwin和Ant的,当然用也可以... 以下用 %PROJEC ...

  2. POJ 2635 The Embarrassed Cryptographer 大数模

    题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...

  3. 【产品体验】喵街&飞凡

    最近O2O很火啊,我也来找几个O2O产品体验下~~~ 阿里今年5月30号上线了一款线下逛街App——喵街,号称消费者的逛街神器.阿里去年已经与银泰合作一年,探索互联网和传统实体零售合作之路,这次则免费 ...

  4. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式

    Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". ...

  5. 【网络流24题】 No.2 太空飞行计划问题 (最大闭合权图 最大流 )

    原题:         W教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合 E={E1,E2,...,Em},和进行这些实验需 ...

  6. Json数据异步绑定到界面的Table并且自动刷新

    转自:http://blog.csdn.net/jianxin1009/article/details/8565828‘ 做Winform习惯了,大家都习惯设置datasource这样的写法. 如果想 ...

  7. Flash加载网页内容

    import flash.net.URLLoader; var m_loader:URLLoader = new URLLoader(); m_loader.addEventListener(Even ...

  8. [PeterDLax著泛函分析习题参考解答]第5章 赋范线性空间

    1. (a) 证明 (6) 定义了范数. (b) 证明它们在 (5) 式意义下是等价的. 证明: $$\bex |(z,u)|'\leq |(z,u)|\leq 2|(z,u)|',\quad |(z ...

  9. [转]NHibernate之旅(5):探索Insert, Update, Delete操作

    本节内容 操作数据概述 1.新建对象 2.删除对象 3.更新对象 4.保存更新对象 结语 操作数据概述 我们常常所说的一个工作单元,通常是执行1个或多个操作,对这些操作要么提交要么放弃/回滚.想想使用 ...

  10. ARM学习笔记15——串口通信基本原理【转】

    计算机串口基本理论 1.什么是串口? 2,什么是RS-232? 3,什么是RS-422? 4,什么是RS-485? 5,什么是握手? 1,什么是串口? 串口是计算机上一种非常通用的设备通信的协议(不要 ...