題目1:bool、int、float定義的變量和0值的比較?函數
(1)bool類型spa
if(flag) if(!flag)
(2)int類型指針
if(flag==0) if(flag!=0)
(3)float類型code
if(flag >= -EPSILON && flag <= EPSILON)
注意float類型是一個浮點型,因此不能夠直接用flag == 0這種形式比較0值。blog
題外話:float類型是小數點後5位有效,double類型是小數點後13位有效。內存
題目二:不調用庫函數實現字符串的拷貝字符串
#include <stdio.h> #include <stdlib.h> #include <string.h> char *copy_string(char *strDes,char *strSou) { int i=0; while(*strSou) { strDes[i++] = *strSou; strSou++; } strDes[i] = '\0'; } int main(int argc,char *argv[]) { char *sou="hello world"; //char des[100]={0}; char *des = (char*)malloc(strlen(sou)+1); //若是寫成指針的形式記得爲它分配內存 copy_string(des,sou); printf("des:%s\n",des); return 0; }