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. react-native-splash-screen 隐藏statusbar

    目录 android ios android android/app/src/main/java/项目名/MainActivity.java @Override protected void onCr ...

  2. Spring Boot结和Spring Data(Ehcache缓存,Thymeleaf页面,自定义异常页面跳转,Swagger2)

    项目结构 pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  3. C++与数据结构课程设计---定票咨询系统

    订票咨询管理系统 设计编制一个订票管理系统,考虑旅客不同的要求.例如,选择不同的交通工具,希望在旅途中的时间尽可能地短,期望旅费尽可能省,或要求中转次数最少等.为旅客提供两种或三种最优决策.车票基本信 ...

  4. POJ 1325 Machine schedine (二分图-最小点覆盖数=最大匹配边数)

    As we all know, machine scheduling is a very classical problem in computer science and has been stud ...

  5. CodeForces-617E XOR And Favorite Numbers(莫队)

    Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is g ...

  6. Zabbix通过与微信、钉钉整合实现实时告警

    abbix可以通过多种方式把告警信息发送到指定人,常用的有邮件,短信报警方式,但是越来越多的企业开始使用zabbix结合微信.钉钉作为主要的告警方式,这样可以及时有效的把告警信息推送到接收人,方便告警 ...

  7. Everspin非易失性MRAM切换技术

    切换MRAM技术 切换MRAM使用1个晶体管,1个MTJ单元来提供简单的高密度存储器.Everspin使用获得专利的Toggle电池设计,可提供高可靠性.数据在温度下20年始终是非易失性的. 在读取期 ...

  8. 联合查询和数据库设计e-r图

    联合查询: 联合查询的关键字是: union 基本含义 联合查询就是将两个select语句的查询结果“层叠”到一起成为一个“大结果”. 两个查询结果的能够进行“联合”的先觉条件是:结果字段数相等. 就 ...

  9. 【JS】376- Axios 使用指南

    点击上方"前端自习课"关注,学习起来~ 来源 | https://www.jianshu.com/p/df464b26ae58 一.axios    基于promise用于浏览器和 ...

  10. HA-高可用集群

    原理:两台web服务器,通过心跳线进行通信,当主节点出现服务异常,备用节点通过探测判断主节点是否存活,若是不存活,就把服务接管过来. Web1和Web2中间有一根心跳线,检查对方的存活状态.流动IP: ...