/*
*规反向输出字符串
*author:jxb
*date:2015\4\4
*
*/
#include <stdio.h>
void reverse(char *str)
{
if (*str == '\0')
{
return 0;
}
else
{
reverse(str+1); //递归;不能使用(str++)
printf("%c",*str);
}
}
int main()
{
char str[100];
printf("please input:\n");
scanf("%s",str);
reverse(str);
printf("\n");
return 0;
}
/*
*fun: printf()参数是从右往左运算,程序输出8,8
*author:jxb
*date:2015\4\5
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
int arr[] = {6,7,8,9,10};
int *p = arr;
*(p++) += 123;
printf("%d %d\n",*p,*(++p));
return 0;
}
/*
*fun: 统计9999的二进制数值中有多少个1
*author:jxb
*date:2015\4\5
*
*/
#include <stdio.h>
#include <stdlib.h>
void main()
{
int c = 0;
int x = 9999;
while(x)
{
c++;
x = x&(x-1); //1000-1 = 0111 相与为0
printf("%x\n",x);
}
printf("c = %d\n",c);
}
注1、 //strlen 字符串长度不含‘\0’
注2、 //main为什么有返回值》返回值是返回给执行的这个进程
注3、 //动态内存分配是为了节省内存空间,用完后马上释放
注4、 //malloc(0)不返回NULL
注5、感谢学习网址-------------》点击打开链接