C语言基础内容
1.打出一定的字符
#include<stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
2.char float double
#include<stdio.h>
int main()
{
char ch ='A';
printf("%c\n",ch);
return 0;
}
#include<stdio.h>
int main()
{
int age = 20 ;
printf("%d\n",age);
return 0;
}
#include<stdio.h>
int main()
{
float f = 5.0;
printf("%f\n",f);
return 0;
}
#include<stdio.h>
int main()
{
double d = 3.14;
printf("%lf\n",d);
return 0;
}
3.计算字节
#include<stdio.h>
int main()
{
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double));
return 0;
}
4.局部变量和全局变量
局部变量与全局变量名字不应该相同,当局部变量与全局变量的名字相同时局部变量优先
extern 外部符号的声明
#include<stdio.h>
int num = 200;
int main()
{
int num =20;
printf("%d\n",num);
return 0;
}
#include<stdio.h>
int num1 = 200;
int main()
{
int num2 =20;
printf("%d%d\n",num1,num2);
return 0;
}
5.计算两个数相加
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
int sum = 0 ;
scanf("%d%d",&a,&b);
sum = a + b ;
printf("sum = %d\n",sum);
return 0 ;
}