#include<stdio.h>// 函数外定义变量 x 和 yint x;int y;intaddtwonum(){// 函数内声明变量 x 和 y 为外部变量externint x;//如果不加extern则为局部变量externint y;// 给外部变量(全局变量)x 和 y 赋值
x =1;
y =2;return x+y;}intmain(){int result;// 调用函数 addtwonum
result =addtwonum();printf("result 为: %d",result);printf("x的值:%d", x);printf("y的值:%d", y);return0;}
#define 定义一个常量 #define PI 3.1415926
const 定义一个常量 const long double PI = 3,1415926
auto 存储类是所有局部变量默认的存储类。 定义在函数中的变量默认为 auto 存储类,这意味着它们在函数开始时被创建,在函数结束时被销毁
#include<stdio.h>intmain(){unsignedint a =60;/* 60 = 0011 1100 */unsignedint b =13;/* 13 = 0000 1101 */int c =0;
c = a & b;/* 12 = 0000 1100 */printf("Line 1 - c 的值是 %d\n", c );
c = a | b;/* 61 = 0011 1101 */printf("Line 2 - c 的值是 %d\n", c );
c = a ^ b;/* 49 = 0011 0001 */printf("Line 3 - c 的值是 %d\n", c );}
#include<stdio.h>charFindMAX(constchar* a,int count)//这里的const是为防止a数组中的数据被改变{char max = a[0];char i;for( i =0; i < count; i++){if(max < a[i]){
max = a[i];}}return max;}intmain(){char a[]={11,11,12,23,56};char max;char count =sizeof(a);
max =FindMAX(a,count);printf("a数组中最大值为-->%d",max);return0;}