If you cant explain it simply, you dont understand it well enough

C 语言基本知识

C 语言基本知识

1. 堆和栈,以及常用内存块

(1) 栈(stack): 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈;

(2) 堆(heap): 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表。

2. 结构体(struct)

#include<stdio.h>

// Only define of struct
struct struct1{
    char name[20];
    float height;
    char job[20];
};
struct struct1 student1 = {"s1",180,"IT"};

// Define first and instantiation
struct stuct2{
    float name[20];
    float height;
    char job[20];
}student2;
student2.name[0] = 's';
student2.height = 190;
student2.job[0] = 't'; 

// typedef
typedef struct _struc{
    char name[20];
    float height;
    char job[20];
}stuc_test;
stuc_test student3 = {"s3",200,"IT"}; // stuc_test equals to struct _struc

int main()
{
    printf ("student1 info: \n");
    return 0;
}   
posted @ 2016-08-10 21:25  zk47  阅读(191)  评论(0编辑  收藏  举报

I am a stupid bird, and I need to work hard