1:switch()后必须是整形表达式,c语言把字符当成整形,所以可以处理字符,但是浮点型和字符串不可以
2:char str = “xiaobo” sizeof(str)为7 有\0的长度
3:http://blog.csdn.net/Veini/article/details/5633874
4:当数组作为函数的形式参数时,可以(而且是通常情况下)不说明数组的长度,例如 int fun(int a[ ]);当需要知道数组的长度时,需要另外一个参数指明其长度
void fun(int a[])
{
int n = sizeof(a);//输出4 a[0]
printf("%d",n);
}
void main()
{
int a[10];
printf("%d\n",sizeof(a));//输出40
fun(a);
}
由以上可以看出sizeof不能在函数中求出数组的长度,传递过去的只是函数的地址
5: int *pInt ; *pInt = 9; 错误,pint还没有地址,int *pInt = new int 在堆中分配链内存,指向链内存中大一块,*pInt = 9; 9赋值给这块内存。
6:翻转字符串的c程序
方法1,需要额外的内存空间
void reversesrc(char *src1)
{
int len = strlen(src1);
char *dest = (char *)malloc(len+1);//申请空间
char *s = &src1[len - 1];//指向最后一个字符
char *d = dest;
while(len--)
{
*d++ = *s--;
}
*d= 0;//尾部加'\0'
printf("%s\n",dest);
free(dest);
dest = NULL;
}
方法2
int main()
{
char str[] = "hello,world";
int len = strlen(str);
int i;
char t;
for(i = 0; i < len/2; i++)
{
t = str[i];
str[i] = str[len - i - 1];
str[len - i - 1] = t;
}
printf("%s",str);
reversesrc(str);
while(1);
}
7:用malloc查看在你的进程中可以分配多大的内存《c专家》
#include"stdio.h"
#include"stdlib.h"
void main()
{
int MB = 0;
while(malloc(1 << 20))++MB;
printf("Allocated %d MB total\n",MB);
}
8:long 4个字节,int在32位上4个字节,在16位系统下2个字节
9:TCP三握手和四次挥手http://www.cppblog.com/csolay/archive/2011/10/22/158859.html
10:进程和线程 http://www.cnblogs.com/engine1984/archive/2007/08/22/865562.html