/*
2016年4月10日10:53:17
功能:static和const的作用
*/
# include <stdio.h>
# include <string.h>
static int j;
void fun1(void)
{
static int i = 0;
i++;
}
void fun2(void)
{
j = 0;
j++;
}
int main(void)
{
int arr[5] = {10, 20, 30};
char mystr[] = "JustAtest\n";
char *ptr = mystr;
const int a = 100; // const的作用,在函数f中不能修改数组元素的值,若修改,编译时会报错
// a = 99; // 编译报错
printf("%d %d %d\n", sizeof(int), sizeof(unsigned int), sizeof(arr));
printf("%d %d\n", sizeof(char), sizeof(mystr));
printf("%d %d %d\n", sizeof(ptr), sizeof(*ptr), strlen(ptr));
fun2();
printf("%d\n", j);
return 0;
}
/*输出结果:
--------------------
4 4 20
1 11
4 1 10
1
*/
static和const的作用
最新推荐文章于 2023-05-16 21:32:56 发布