C lang:Pointer operation
Xx_Pointer opteration
Do not dereference initialized Pointers
Ax_Code
#include<stdio.h>
int main(void)
{
int urn[5] = { 100, 200, 300, 400, 500 };
int * ptr1, *ptr2, *ptr3;
int a =2;
ptr1 = urn; // equal to &urn[0]
ptr2 = &urn[2];
printf("%p,%p,%p\n",urn,&urn,&a);
printf("pointer value, dereferenced pointer, pointer address:\n");
printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);
// pointer addition
ptr3 = ptr1 + 4;
printf("\nadding an int to a pointer:\n");
printf("ptr1 + 4 = %p, *(ptr1 + 4) = %d\n", ptr1 + 4, *(ptr1 +4));
ptr1++; // increase
printf("\nvalues after ptr1++:\n");
printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);
ptr2--; // decrease
printf("\nvalues after -ptr2:\n");
printf("ptr2 = %p, *ptr2 = %d, &ptr2 = %p\n", ptr2, *ptr2, &ptr2);
--ptr1;
--ptr2;
printf("\nPointers reset to original values:\n");
printf("ptr1 = %p, ptr2 = %p\n", ptr1, ptr2);
// ont pointer minus another pointer.
printf("\nsubtracting one pointer from another:\n");
printf("ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %td\n", ptr2, ptr1, ptr2 - ptr1);
// ont pointer minus a integer.
printf("\nsubtracting an int from a pointer:\n");
printf("ptr3 = %p, ptr3 - 2 = %p\n", ptr3, ptr3 - 2);
return 0;
}
Assign: assign a pointer to a pointer.It can be the name of an array, the name of an address variable, or a pointer
The dereference: * operator gives the pointer to the value stored at the address.(this is the pointer.)
Address: like all variables, a pointer variable has its own address and reference, & itself.Store the address to memory.
Pointer plus integer: the integer is multiplied by the size of the pointing type (int is 4) and then added to the initial address.(you can't go beyond the array, but you can reasonably go
beyond it.Right at the end of the first position, which is allowed.)
Incrementing pointer: incrementing a pointer to an array element can move the pointer to the next element in the array.If int = + 4 (because int = 4, double = 8)
Pointer minus an integer: the pointer must be the first operand that integer is multiplied by the size of the pointing type and then subtracted by the initial value.
Decrement pointer: you can increment or decrement.
Difference of pointer: the difference of pointer can be calculated (this difference is the number of types, the distance in the same array).
Comparison: two Pointers of the same type are compared using the relational operator.
C lang:Pointer operation的更多相关文章
- Delphi的"Invalid pointer operation"异常的解决办法
今天用Delphi编写了个dll,用到了TStringList来传递多参数,如下: [delphi] view plaincopy 01.function DBM_SetParam(procName: ...
- C lang:Pointer and multidimensional array
Xx_Introduction Double indrection:Address of Address;Pointer of Pointer Ax_Code #include<stdio.h& ...
- C lang:Pointer and Array
Xx_Introduction Point and Array germane. Xx_Code #include<stdio.h> #define SIZE 4 int main(voi ...
- C lang: Pointer
Ax_Terminology xa_pointer pointer is the address used to store the variable;A variable (or data obje ...
- Delphi的分配及释放---New/Dispose, GetMem/FreeMem及其它函数的区别与相同
转载自:http://www.cnblogs.com/qiusl/p/4028437.html?utm_source=tuicool 我估摸着内存分配+释放是个基础的函数,有些人可能没注意此类函数或细 ...
- delphi.memory.分配及释放---New/Dispose, GetMem/FreeMem及其它函数的区别与相同
我估摸着内存分配+释放是个基础函数,有些人可能没注意此类函数或细究,但我觉得还是弄明白的好. 介绍下面内存函数前,先说一下MM的一些过程,如不关心可忽略: TMemoryManager = recor ...
- bug_ _ _常见的bug??
======= 7 Failure [INSTALL_FAILED_INVALID_APK] 执行 adb install -r test.apk.时出现错误 Failure [INSTAL ...
- free pascal 错误代码表
free pascal 错误代码表 为了方便对照检查运行时错误代码,这里把所有的错误代码的含义整理出来.(最大序号为232,中间不一定连续.user.pdf P175) Run-time errors ...
- OpenGL顶点缓冲区对象(VBO)
转载 http://blog.csdn.net/dreamcs/article/details/7702701 创建VBO GL_ARB_vertex_buffer_object 扩展可 ...
随机推荐
- Java修炼——面向对象_抽象类和抽象方法
抽象类和抽象方法 什么是抽象类? 使用 abstract 修饰的类称为抽象类 public abstract class Person { } 抽象类的特征 1) 抽象类不可以创建对象 2) 抽象类可 ...
- 详解TCP连接的“三次握手”与“四次挥手”(下)
上文链接: 详解TCP连接的"三次握手"与"四次挥手"(上) 四.TCP的四次挥手(Four-Way Wavehand) 0.前言 对于"三次握手&q ...
- [TimLinux] WireShark 安装篇——CentOS7
1. 下载 libpcap: http://www.tcpdump.org/release/libpcap-1.9.0.tar.gz cmake: https://github-production- ...
- (全国多校重现赛一)B-Ch's gifts
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...
- ARTS-S C语言多线程传参数
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h& ...
- Selenium 4.0 Alpha更新实践
上期讲到了Selenium 4.0 Alpha更新日志,这次来实践一下更新内容. DevTools操作更加方便. Chrome录制更加方便.(未实践) 窗口管理不在依赖一个driver. 相对定位器功 ...
- 【Java Web开发学习】Spring配置数据源
Spring配置数据源 转载:https://www.cnblogs.com/yangchongxing/p/10027495.html =============================== ...
- 《Java基础知识》Java方法重载和重写
重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变.即外壳不变,核心重写! 重写的好处在于子类可以根据需要,定义特定于自己的行为. 也就是说子类 ...
- java基础集合简介Set(三)中
今天主要说夏set集合,每天抽出一个小时总结下,生活会更加美好! --< java.util >-- Set接口: 数据结构:数据的存储方式: Set接口中的方法和Collection中方 ...
- 浅析堆栈段,BBS段,数据段,代码段
文章目录 1. 进程,线程 2. 堆栈段 3. BBS段 4. 代码段 5. 数据段 6. 例子 7. 总结 1. 进程,线程 所谓进程是指在系统中能独立运行并作为资源分配的基本单位,程序段,数据段和 ...