1.
#define pi 3.14
#define Area(R) pi*R*R
main()
{
int r1=5,r2=2;
double s=0;
s=Area(r1-r2);
printf("The area is %f",s);
}
求結果: The area is 3.700000
2.函數 int compare(int a,int b),定義爲該函數的函數指針P:爲 int(*p)(int,int);p= compare;
3.求輸出結果
#include
void sub(char*s,int num)
{
int i ,j=num;
char t;
while(j-->1)
{
for(i=0;i
{
if(s[i]
{
t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
}
}
}
main()
{
char *s="CEAeded";
sub(s,6);
printf("%sn",s)
}
輸出結果:運行時程序崩潰,
//4**********************************************
//交換兩個變量的值,不使用第三個變量,即a=3,b=5交換
//後b=3,a=5
unsigned char a=3,b=5;
//5**************************************************
#define N 100
void GetMemory1(char*p)
{
p=(char*)malloc(sizeof(char)*N);
strcpy(p,"Have a good day!");
}
char*GetMemory2(void)
{
char p[]="Have a good day!";
return p;
}
void main(void)
{
char*str1=NULL,*str2=NULL;
GetMemory1(str1);
GetMemory2(str2);
printf("nstr1:%s",str1);
printf("nstr2:%s",str2);