/*
* 1. 动态开辟二维数组
* 2. extern 关键字 -> 外部的
* a.cpp 定义 int a = 222;
* b.cpp 使用 a变量。先声明变量a extern int a; 源文件中已经定义过a,编译器LINK 变量
* 3. 变量:普通局部变量: 函数中定义的变量 .stack 只声明未定义 随机
普通全局变量: 函数外定义的变量 .data 只声明未定义 类型默认值
static 静态修饰局部变量 -> 局部静态变量
static静态修饰全局变量 -> 全局静态变量#include<stdio.h> #include<stdlib.h> #include<string.h> //#include"a.h" //预编译阶段 头文件 展开到当前文件 #define ROW 3 #define COLUMN 4 extern int a; //声明a变量已经被定义过(本文件/其他源文件) //void fun(); //声明在本文件中定义过fun函数 extern void fun(); void func() { static int a;//静态局部变量 printf("%d\n", a);//若a定义在其他源文件中 } int main() { char c = -1;//二进制为1111 1111 unsigned char d = (unsigned char)c;//强转为无符号的 char,类型 d=255; printf("%d", d); func(); int** brr = (int**)malloc(sizeof(int*)*ROW); if (brr == NULL) return -1; for (int i = 0; i < ROW; i++) { brr[i] = (int*)malloc(sizeof(int)*COLUMN); memset(brr[i], 0, sizeof(int) * COLUMN);//初始化brr,给每个数组赋值为0 } for (int i = 0; i < ROW; i++) { for (int j = 0; j < COLUMN; j++) { printf("%d ",brr[i][j]); } printf("\n"); } return 0; } void fun() { printf("fun()"); }
4..text: 文件 ->代码段区->函数调用
.data 数据:全局变量,字符串常量
.heap 堆区 :动态内存 申请(malloc realloc calloc) 释放
.stack 栈区 函数局部变量
5.static 文件作用域