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. JavaMail 发送邮件

    JavaMail邮件发送 引用maven jar包 <dependency> <groupId>javax.mail</groupId> <artifactI ...

  2. 5个有用的.net profiling工具(转)

    我们有时需要对研发的软件程序进行性能测试,这时需要用到一些Profilers工具.下面列出5个有用的.net Profilers: 1. JetBrains dotTrace JetBrains do ...

  3. 关于OJ的输入和输出(转)

    ACM竞赛之输入输出以下内容来源于互联网.在ACM程序设计竞赛中,一道题目的所有测试数据是放在一个文本文件中,选手将一道题目的程序提交给评判系统运行,程序从该文件中读取测试数据,再把运行结果输出到另一 ...

  4. bzoj 1070: [SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2785  Solved: 1110[Submit][Status] ...

  5. 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)

    [题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...

  6. WIN32和Kernel)直接读写硬盘扇区

    第一篇写技术的文章哦,以前好少写文章,我的文字表达很差劲,大家不要笑哦.前几天仙剑4通关了,感觉好惆怅,什么都不想去做.今天看了一下书发现一篇比较好玩的文章,于是自己静静地实践一番.文章是<基于 ...

  7. 【简译】Windows 线程基础

    翻译一篇关于windows线程的文章,原文在此.第一次翻译,如有错误请多指教 =========================================华丽的分割线============== ...

  8. 数据库设主键以及where的应用

    二.第二课 create table teacher ( tno int primary key identity(1,1),  --将tno设为主键(primary key identity(1,1 ...

  9. createElement

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. spm_预处理实验记录

    参考:<SPM8 MANNUAL> Chapter 28 Auditory fMRI data