C基础(31——35)
来源:互联网 发布:mac mini macbook air 编辑:程序博客网 时间:2024/05/22 10:24
大端:数据的高位字节存放在地址的低端,低位字节存放在地址的高端
小端:数据的高位字节存放在地址的高端,低位字节存放在地址的低端
即
大端是按照数字的书写顺序进行存储
小端是颠倒书写顺序进行存储
#include <stdio.h>#include <stdlib.h>void test(){ int a=1; char* p=(char *)(&a); if(*p==1) printf( "Little_Endian\n"); else printf( "Big_Endian\n");}int main(){ test(); system( "pause"); return 0;}//一个时间点,只有一个变量可用//union UN//{// char c;// int i;//}un;//int main()//{// un.i=1;// if(un.c==1)// printf("Little_Endian\n");// else// printf("Big_Endian\n");//// system("pause");// return 0;//}
结果:
#include <stdio.h>#include <stdlib.h>void test(){ int a=0; int b=0; printf( "a="); scanf( "%d",&a); printf( "b="); scanf( "%d",&b); a=a+b; b=a-b; a=a-b; printf( "交换之后\na=%d\nb=%d\n" ,a,b);}int main(){ test(); system( "pause"); return 0;}
结果:
#include <stdio.h>#include <stdlib.h>void test(){ int i=1; int count=0; for(;i<=100;i++) { int a=i; while(a) { if(a%10==9) count++; a=a/10; } } printf( "total=%d\n",count);}int main(){ test(); system( "pause"); return 0;}
结果:
#include <stdio.h>#include <stdlib.h>#define N 10void test(){ int i=0; int arr[N ]={0}; int count=0; printf( "请输入一个数:" ); scanf( "%d",&i); if(i==0) printf( "%d",0); while(i) { arr[count]=i%10; count++; i=i/10; } for(int m=count;m>0;m--) { printf( "%d ",arr[m-1]); } printf( "\n");}int main(){ test(); system( "pause"); return 0;}
结果:
#include <stdio.h>#include <stdlib.h>//相当于库函数中的strchr,strchr()将会找出str字符串中第一次出现的字符c的地址,然后将该地址返回//如果找到指定的字符,则返回该字符所在的地址,否则返回NULL//如果查找某字符在字符串中最后一次出现的位置,可使用strrchr()函数int Find_Index(char * s,char c){ int index=0; while(*s !='\0') { if(*s ==c) return index+1; s++; index++; } return NULL ;}char* Find_Address(char * s,char c){ int index=0; while(*s !='\0') { if(*s ==c) return s ; s++; index++; } return NULL ;}void test(){ char* str="0a,20b,123*cd,ef." ; int i=Find_Index(str,'0' ); char* p=Find_Address(str,'0' ); printf( "%d\n",i); printf( "%p\n",p);}int main(){ test(); system( "pause"); return 0;}
结果:
本文出自 “追寻内心的声音” 博客,请务必保留此出处http://ljy789.blog.51cto.com/10697684/1832221
0 0
- C基础(31——35)
- C#——基础
- c基础—5
- Object—C基础
- C#—基础语法
- C基础—内存
- C基础(11——15)
- C基础(16——20)
- C基础(21——25)
- C基础(26——30)
- C基础(36——40)
- C基础(41——45)
- C基础(46——50)
- 基础练习——百钱买百鸡(C++)
- iOS基础(c)—函数
- iOS基础(c)—指针
- iOS基础(c)—数组
- c++/c 学习笔记——基础(2)
- java基础—— String与InputStream互转的几种方法
- Android主题切换方案总结
- 码神培训心得
- GetProcAddress()用法
- Activiti实战--书籍阅读导读
- C基础(31——35)
- C基础(36——40)
- C、C++中union用法总结
- C基础(41——45)
- libreoffice calc 插入多行
- Oracle执行计划不走索引的原因总结
- UGUI能量图
- 野兽派游戏
- MathType6.7安装后word2007的功能区(工具栏)无显示