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的更多相关文章

  1. Delphi的"Invalid pointer operation"异常的解决办法

    今天用Delphi编写了个dll,用到了TStringList来传递多参数,如下: [delphi] view plaincopy 01.function DBM_SetParam(procName: ...

  2. C lang:Pointer and multidimensional array

    Xx_Introduction Double indrection:Address of Address;Pointer of Pointer Ax_Code #include<stdio.h& ...

  3. C lang:Pointer and Array

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

  4. C lang: Pointer

    Ax_Terminology xa_pointer pointer is the address used to store the variable;A variable (or data obje ...

  5. Delphi的分配及释放---New/Dispose, GetMem/FreeMem及其它函数的区别与相同

    转载自:http://www.cnblogs.com/qiusl/p/4028437.html?utm_source=tuicool 我估摸着内存分配+释放是个基础的函数,有些人可能没注意此类函数或细 ...

  6. delphi.memory.分配及释放---New/Dispose, GetMem/FreeMem及其它函数的区别与相同

    我估摸着内存分配+释放是个基础函数,有些人可能没注意此类函数或细究,但我觉得还是弄明白的好. 介绍下面内存函数前,先说一下MM的一些过程,如不关心可忽略: TMemoryManager = recor ...

  7. bug_ _ _常见的bug??

    ======= 7    Failure [INSTALL_FAILED_INVALID_APK] 执行  adb install -r test.apk.时出现错误  Failure [INSTAL ...

  8. free pascal 错误代码表

    free pascal 错误代码表 为了方便对照检查运行时错误代码,这里把所有的错误代码的含义整理出来.(最大序号为232,中间不一定连续.user.pdf P175) Run-time errors ...

  9. OpenGL顶点缓冲区对象(VBO)

    转载 http://blog.csdn.net/dreamcs/article/details/7702701 创建VBO        GL_ARB_vertex_buffer_object 扩展可 ...

随机推荐

  1. spring-MVC_笔记

    需求:客户端发起请求,服务器端接收请求,执行逻辑并进行视图跳转. ①导入SpringMVC相关坐标②配置SpringMVC核心控制器DispathcerServlet ③创建Controller类和视 ...

  2. mysql的安装及命令

    1.先检查系统是否装有mysql rpm -qa | grep mysql 2.下载mysql的repo源 wget     http://192.168.130.150/mysql5.7.26/my ...

  3. 卸载&&更新docker(ubuntu)

    卸载docker: apt-get purge lxc-docker apt-get autoremove 更新docker: apt-get update apt-get install lxc-d ...

  4. luogu P2417 课程

    题目描述 n个学生去p个课堂,每一个学生都有自己的课堂,并且每个学生只能去一个课堂,题目要求能够安排每一个课堂都有人吗? 输入格式 第一行是测试数据的个数, 每组测试数据的开始分别是p和n, 接着p行 ...

  5. The file “XXX.app” couldn’t be opened because you don’t have permission to view it.问题修复

    出现下列问题 怎么解决呢 如图 将info.plist的文件中的Executable.file中的文件修改为:$(PRODUCT_NAME) 重新编译 com+R不出意外的话 运行成功 ok 解决~

  6. openlayers6结合geoserver实现地图属性查询(附源码下载)

    前言 之前写过一篇 openlayers4 版本的地图属性查询文章,但是由于是封装一层 js 代码写的,很多初学者看起来比较有点吃力,所以本篇文章重新写一篇地图属性查询文章,直接基于最新版本 open ...

  7. PHP原生实现简易的MVC框架

    目录结构: —|controller —|Home.php —|model —|view —|welcome.php —|index.php 基本原理: 首页 index.php 通过获得地址栏中的路 ...

  8. Shell排序 C&&C++

    Shell排序   Shell排序是大量数据需要排序时,更为高效的插入排序.它的算法思想基于插入排序的算法思想 流程: (1)将n个元素数组分成n/2个数字序列,第一个数据和第n/2个数据为一对,等等 ...

  9. 【Java Web开发学习】Spring MVC文件上传

    [Java Web开发学习]Spring MVC文件上传 转载:https://www.cnblogs.com/yangchongxing/p/9290489.html 文件上传有两种实现方式,都比较 ...

  10. 4个点让你彻底明白Redis的各项功能

    前言 先看一下Redis是一个什么东西.官方简介解释到: Redis是一个基于BSD开源的项目,是一个把结构化的数据放在内存中的一个存储系统,你可以把它作为数据库,缓存和消息中间件来使用.同时支持st ...