C语言程序阅读-变量的存储类别、函数及参数

简介: 写出程序运行结果,再运行程序进行比较。 (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) { sta

写出程序运行结果,再运行程序进行比较。
(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

目录
相关文章
|
16天前
|
程序员 C语言
C语言库函数 — 内存函数(含模拟实现内存函数)
C语言库函数 — 内存函数(含模拟实现内存函数)
26 0
|
27天前
|
编译器 C语言 C++
【C语言】memset()函数(内存块初始化函数)
【C语言】memset()函数(内存块初始化函数)
26 0
|
27天前
|
编译器 C语言 C++
【C语言】memcpy()函数(内存块拷贝函数)
【C语言】memcpy()函数(内存块拷贝函数)
42 0
|
18天前
|
存储 编译器 C语言
深入探索C语言动态内存分配:释放你的程序潜力
深入探索C语言动态内存分配:释放你的程序潜力
28 0
|
1天前
|
C语言
C语言:内存函数(memcpy memmove memset memcmp使用)
C语言:内存函数(memcpy memmove memset memcmp使用)
|
1天前
|
C语言
C语言:字符函数和字符串函数(strlen strcat strcmp strncmp等函数和模拟实现)
C语言:字符函数和字符串函数(strlen strcat strcmp strncmp等函数和模拟实现)
|
3天前
|
存储 C语言
C语言动态存储方式与静态存储方式
C语言动态存储方式与静态存储方式
7 0
|
3天前
|
存储 C语言
C语言函数的返回值
C语言函数的返回值
7 0
|
3天前
|
C语言 Windows
C语言中的fopen与fclose函数详解
C语言中的fopen与fclose函数详解
11 1
|
3天前
|
C语言
深入理解C语言中的printf函数及数据输出
深入理解C语言中的printf函数及数据输出
13 0