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 扩展可 ...
随机推荐
- Internet History,Technology,and Security - Dawn of Electronic Computing(Week 1)
一 War Time Computing and Communication 讲到电子计算机,你不得不提起第二次世界大战,虽说二战是人类历史上史无前例的大灾难,不过从某种程度来说,它确实促进了社会的发 ...
- linux 通过管道更方便的查询输入记录
history |sort -k4|uniq -f3 -c |sort -n -k2 history:得到输入记录|sort -k4:在第4列进行排序 -k4 第4列 每一列用空格分隔|uniq -f ...
- MacOS下制作linux启动盘
在Windows下,我们经常使用软碟通来制作各种系统的启动盘,那么在MacOS下,如何做到呢?MacOS跟Linux的做法基本一致.如果你只想快速地制作好启动盘,请看下面的快速版 首先,你需要以下两样 ...
- ARTS-S k8s配制文件demo
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: go-demo-hostname spec: replicas: 2 t ...
- usb fx2 cy68013 Cyapi使用心得
Cyapi使用心得(1)--USB连接 用Cyapi也有一阵了,这个确实比EZusb的api好用,简单说下Cyapi的使用心得,在编程中应该注意的一些问题,毕竟,说起来,那个CYapi的说明文档讲的实 ...
- vue2.5 + element UI el-table 导出Excel
安装依赖 npm install --save xlsx file-saver 新建excelHelper.js \src\utils\目录下新建excelHelper.js文件 import Vue ...
- 【JS】327- javascript 的 api 设计原则
点击上方"前端自习课"关注,学习起来~ 前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博 ...
- 【CSS】318- CSS实现宽高等比自适应容器
点击上方"前端自习课"关注,学习起来~ 在最近开发移动端页面,遇到这么一个情况:当页面宽度 100% 时,高度为宽度一半,并随手机宽度变化依然是一半. 于是我们就需要实现一个宽度自 ...
- NIO-SocketChannel源码分析
目录 NIO-SocketChannel源码分析 目录 前言 ServerSocketChannelImpl 创建ServerSocketChannel 绑定和监听 接收 SocketChannelI ...
- 用递归实现N!
def digui(n): result = 1 if n == 2: result = 2 elif n > 2: result = n* digui(n-1) print(result) r ...