大端:数据的高位字节存放在地址的低端,低位字节存放在地址的高端
小端:数据的高位字节存放在地址的高端,低位字节存放在地址的低端
即
大端是按照数字的书写顺序进行存储
小端是颠倒书写顺序进行存储
#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 10
void 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