tips:
sizeof:运算符,获得保证能容纳实现所建立的最大对象的字节大小。
strlen:函数,测量字符的实际长度,以’\0’作为结束,但不会记录‘\0’,而sizeof测量的字符的分配大小
一、指针与数组
A>
B>
C>数组与指针
#include <stdio.h>
int main()
{
int a[]={2,3,2,3};
int *ptr1=(int *)(&a+1); //0x3
int *ptr2=(int *)((int)a+1); // 0x3000000
printf("0x%x 0x%x \n", ptr1[-1], *ptr2);
return 0;
}
假设a地址是00h,所以地址与内存的关系是:(数据低字节低地址)
00h ---- 0x02
01h ---- 0x00
02h ---- 0x00
03h ---- 0x00
04h ---- 0x03
~~~
0Ch ---- 0x03
0Dh ---- 0x00
0Eh ---- 0x00
0Fh ---- 0x00
第一个(int *)(&a+1)中(&a+1)是指跳过一整个数组到达数组末尾地址为10h,
后面输出ptr1[-1] 是在10h位置上后退4个字节,即a[3] = 3 ---> 0x3
第二个(int *)((int)a+1)中,((int)a+1)是先把a从地址数据强行转换成整型数据,
即将原来00h ---> 0x00 + 1 ---> 0x01
再强行转换成地址数据即0x01 ---> 01h
输出就是从01h~04h 得到 0x 30 00 00 00
二、函数 ---- 递归
//数字转成字符一个一个输出
#include <stdio.h>
void ascii(unsigned int value)
{
unsigned int quotient;
quotient = value / 10;//去低位数
if(quotient != 0)
ascii(quotient);
putchar(value%10 + '0');//得低位数
printf("\n");
}
int main()
{
ascii(4267);
return 0;
}
解释递归