指针的运算符
来源:互联网 发布:短信监控软件 编辑:程序博客网 时间:2024/06/05 19:33
指针的运算符
指针的加法:
int *p =xxxx;
p+1 ==》 xxxx+1*(sizeof(*p))
指针的加法运算,实际上加的是一个单位,单位的大小可以使用sizeof(*p)- 指针的减法:
指针的减法与加法类似,都是一个单位进行相应的操作。 自加、自减:
在这个过程中指针也变换,更新了指针的地址。[]的使用
变量名[n]: ID名+标签,是一个地址内容的标签访问,类似于数组。可以对指针进行跳跃访问。例子:
#include <stdio.h> int main (void ) { int a = 0x12345678; int b = 0x99999119; int *p1 = &b; char *p2 = (char *)&b; printf("the p1+1 is %x,%x,%x\n",*(p1+1)),p1[1],*p1+1); printf("the p2+1 is %x,%x,%x\n ",p2[1]); return 0; }
以下是一个比较字符串并且排序首字母的程序,同时增加了一个忽略大小写排序的子程序。
#include <stdio.h>#include <string.h>#include <ctype.h>#define SIZE 81#define LIM 20#define HALT " "void stsrt (char *string[],int num);void ToUpper(char *str);int main (void ){ char input[LIM][SIZE]; char *ptstr[LIM]; int ct = 0; int k; printf("Input up to %d lines,and I will sort them.\n",LIM); printf("To stop,press the Enter key at a line's start .\n"); while(ct<LIM && gets(input[ct])!=NULL && input[ct][0]!='\0') { ptstr[ct] = input [ct]; ct++; } stsrt(ptstr,ct); puts("\n Here's the sorted list: \n"); for(k=0;k<ct;k++) puts(ptstr[k]); return 0;}void stsrt (char * string[],int num){ char *temp; int top,seek; unsigned int i; char tem_1[50]; char tem_2[50]; for (top=0;top<num-1;top++) for(seek=top+1;seek<num;seek++) { strcpy(tem_1,string[top]); strcpy(tem_2,string[seek]); ToUpper(tem_1); ToUpper(tem_2); if (strcmp(tem_1,tem_2)>0) { temp = string[top]; string[top] = string[seek]; string[seek]= temp; } } }void ToUpper (char * str){while(*str){ str= toupper (*str); str++;}
}
0 0
- 指针的运算符
- 成员运算符(.)与指针运算符(->)的区别
- 类型转换运算符和指针运算符的重载
- 指针运算符的混合运算与优先级
- 指针的自增运算符用法
- 指针中的运算符的结合性
- 指针变量的运算
- 指针的算术运算
- 指针的运算
- 指针的加减运算
- 指针的算术运算
- 指针的运算
- 指针的运算总结
- 指针的运算
- 指针的运算
- 指针的重要运算
- 指针变量的运算
- 指针变量的运算
- The Java™ Tutorials — Concurrency :Atomic Access 原子访问
- 主成分分析PCA
- 九度oj_题目1489:计算两个矩阵的乘积
- BZOJ 1101: [POI2007]Zap|莫比乌斯反演
- leetcode(207) Course Schedule即拓扑排序讲解
- 指针的运算符
- Markdown基础笔记
- android:fitsSystemWindows的作用
- Android回调Callback的理解(附demo)
- Logcat使用小技巧——多Tag过滤。
- 程序猿必备认知!
- 【 bzoj 2400 】Spoj 839 Optimal Marks - 最小割
- 序列图(sequence)语法
- 利用xcode查看UI层级关系