the application of pointer
来源:互联网 发布:php 文章发布系统源码 编辑:程序博客网 时间:2024/04/29 18:10
Today , the pointer waste me amounts of time;
Last , I find the errror is where when I define the located
pointer, but I can't assignment the first value, so , when I
call it any time, the vlaule may be different , so when we
definite the pointer, we must assign the first value to it,
even is NULL, and secondly, I found a secrete of
pointer,
example,
unsigned char *p = NULL;
指针p的值是定死的,指针里存储的类型是 unsigned char 型
unsigned int *p = NULL;
指针p的值是定死的,指针里存储的类型是unsigned int型,
所以针对指针进行访问,指针会根据他的类型传递几个字节给你。
强制类型指针的转换
addr = 0xfe00;
unsigned char number1;
unsigned int number;
number1 = *(unsigned char *)(addr);
这里指针会传递一个字符型的
number2 = *(unsigned int *)(addr);
这里指针会传递一个int型的
关于sizeof的使用(注意sizeof 记到\0, 结果应该加上\0)
1、数组上
char abc[100] = {0};
sizeof(abc) =>> 100;
sizeof(*abc) >> 1,//一个成员占用了1个字节
int bcd[100] = {0};
sizeof(bcd) >> 400;
sizeof(*bcd) >> 4;
char abc[] = "123";
sizeof(abc) >> 4 ;结果加上了\0
sizeof(*abc) >> 1;
2、指针
char *p = "abc";
sizeof (p) >> 4; //一个指针占用了四个字节空间
sizeof(*p) >> 1//一个成员占用了1个字节
int *p = "234";
sizeof(p) >> 4;//一个指针占用四个字节空间
sizeof(*p) >> 4;//一个成员占用四个字节空间
3、strlen的使用
strlen的使用不分数组和字符串,传递的参数是字符型指针,判断长度时候,只要遇到\0就停止,不包括\0;
char *p = "abcded";
strlen(p) >>6 //占用六个字节
char p[100] = {a, b};
strlen(p) >> 2;//占用两个字节
int p[100] = {123};
strlen ((char *)p) >> 1//占用一个字节
int p[100] = {65535];
strlen ((char *)p) >> 2//占用两个字节
int p[100] = {65536];
strlen((char *)p) >> 3//占用三个字节
- the application of pointer
- The pointer of function
- the type of a pointer
- c++: the hint of pointer
- The application of the static
- The uses of Application Engine
- The Target of Cocoa application
- The amazing efficiency of pointer in C Programming Language
- How to use the pointer of function in a class?
- Relationship of the this pointer and (non-)const member function
- [Swift] function pointer(address) as the parameter of function
- Is the type of “pointer-to-member-function” different from “pointer-to-function”?
- A pointer to an object & A pointer one past the end of a different object
- The introduction and application of PLC
- The Architecture of Open Source Application
- The Principles of Java Application Performance Tuning
- RFC3117 - On the Design of Application Protocols
- The Principles of Java Application Performance Tuning
- 搭建Android开发环境搭建过程
- Counting the on hand quantities by API inv_quantity_tree_pub.query_quantities
- Android的线程池:ExecutorService和Executors
- 常用的正则表达式
- Quartz 2D编程指南(5) - 变换
- the application of pointer
- 冒泡排序
- 快速排序
- request_threaded_irq
- PHP常用正则表达式汇总
- ENUM和SET类型 mysql
- 让计算机来计算一元二次方程等式
- Oracle锁表查询及解锁kill
- ACE命令参数解析