C语言程序阅读-变量的存储类别、函数及参数
2016-11-22 22:10
323 查看
写出程序运行结果,再运行程序进行比较。
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(1)
#include<stdio.h> int f(int n); int main() { printf("%d\n", f(5)); printf("%d\n", f(8)); return 0; } int f(int n) { static int a=2; int b=0; a+=n; b+=a; return b; }
(2)
#include<stdio.h> void add() { int x=0; static int y=0; printf("%d,%d\n",x,y); x++; y=y+2; } int main() { int i; for(i=0; i<2; i++) add(); return 0; }
(3)
#include<stdio.h> int x=2; void cude() { x=x*x*x; printf("%d ",x); } int main() { x=5; cude(); printf("%d ",x); return 0; }
(4)
#include <stdio.h> int main() { int *p1,*p2,*p; int a=5,b=8; p1=&a; p2=&b; if(a<b) { p=p1; p1=p2; p2=p; } printf("%d,%d\n",*p1,*p2); printf("%d,%d\n",a,b); return 0; }
(5)
#include<stdio.h> void fun(int x,int y,int *z) { x*=x; y*=y; *z=x+y; } int main() { int a=5,b=2,c=31; fun(a,b,&c); printf("%d %d %d\n",a,b,c); return 0; }
(6)
#include<stdio.h> int a, b; void fun(int *p1, int *p2) { *p1=&a;*p2=&b; *p1=100;*p2=200; } int main() { int a=5, b=7; fun(&a, &b); printf("%d %d\n", a, b); return 0; }
(7)
include
include
相关文章推荐
- 5、对变量在栈上存储顺序,及函数返回值与参数在栈上存放顺序的思考(3)
- 3、对变量在栈上存储顺序,及函数返回值与参数在栈上存放顺序的思考(1)
- C++之内置函数、函数模板、变量的存储类别、类、析构函数、指针
- 变量的存储类别 内部函数和外部函数
- 变量的存储类别、内外部函数【static\extern】
- C++学习 【4.5】 利用函数实现指定的功能---局部变量、全局变量、变量的存储类别、声明和定义
- 4、对变量在栈上存储顺序,及函数返回值与参数在栈上存放顺序的思考(2)
- 第六章 函数/变量存储类别
- 也谈C++深拷贝、浅拷贝和函数返回值作参数及其临时变量的生存期
- 在c#中的取得sql存储过程的output参数及自增列@@identity变量
- 转:Mysql存储过程学习笔记--变量、参数、注释收藏
- strcat()函数的第二个参数是整形变量时,如何转换成char *
- 变量指针和函数参数
- 变量指针和函数参数
- Tokyo Cabinet TCHDB源码阅读——关于变长变量的高效存取(节约存储空间)
- 作为函数参数的临时变量的引用必须是const的
- 只带一个参数变量的存储过程
- 函数不能返回临时变量,可以采用输出参数形式
- C里面的内存动态分配函数与存储类别
- LoadRunner lr_eval_string() 函数使用及LR中变量、参数的简单使用