• 内存管理




    //
    // main.c // 内存管理 // // Created by zhangxueming on 15/6/5. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #include <stdio.h> #include "File.h" //内存管理 //.text: 存储二进制可执行程序 //.data: 初始化的全局变量及初始化的static关键字修饰的变量, 分为只读数据段及可读可写数据段, 只读数据段存储常量如: "helloworld" //.bss: 未初始化的全局变量及未初始化的static修饰的变量 //.heap: 堆内存, 手动申请, 手动释放 //.stack: 栈内存, 局部变量 //static 关键字 //1. 修饰局部变量,全局变量的生命周期, 局部变量的作用域 //2. 修饰全局变量,全局变量只能在当前定义的文件可以访问 //3. 修饰函数,函数只能在定义的文件内使用, 其它外部文件不可以调用 int main(int argc, const char * argv[]) { print_num(); print_num(); set_score(100); printf("score = %d ", get_score()); print(); return 0; }
    //
    //  File.c
    //  内存管理
    //
    //  Created by zhangxueming on 15/6/5.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #include "File.h"
    
    static int score = 88;
    
    void print_num(void)
    {
        static int num = 100;//只有在该函数第一次调用的时候才会定义num变量
        for (int i=0; i<5; i++) {
            printf("num = %d
    ", num++);
        }
    }
    
    void set_score(int value)
    {
        score = value;
    }
    
    int get_score(void)
    {
        return score;
    }
    
    //修饰函数
    
    static void print_hello(void)
    {
        printf("hello wolrd
    ");
    }
    
    static void print_welcome(void)
    {
        printf("welcome
    ");
    }
    
    void print(void)
    {
        print_hello();
        print_welcome();
    }
    //
    //  File.h
    //  内存管理
    //
    //  Created by zhangxueming on 15/6/5.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #ifndef ________File__
    #define ________File__
    
    #include <stdio.h>
    
    void print_num(void);
    
    void set_score(int value);
    int get_score(void);
    
    void print(void);
    
    #endif /* defined(________File__) */
  • 相关阅读:
    纯CSS打造圆角Table效果
    [RabbitMQ+Python入门经典] 兔子和兔子窝[转]
    salesforce 调用webservice
    maven+spring+cxf编写web service
    Appfuse 教程
    eclipse的maven project,如何添加.m2里的那些jar包?
    java fullstack 框架
    Maven Jetty Plugin运行配置jetty:run
    Appfuse下载及安装步骤
    fullstack设计
  • 原文地址:https://www.cnblogs.com/0515offer/p/4555017.html
Copyright © 2020-2023  润新知