当前位置:网站首页>局部变量的数组初始化问题
局部变量的数组初始化问题
2022-07-06 23:08:00 【疯疯癫癫才自由】
当数组不是全局变量时:
如果数组大小是变量,则数组初始化为0时,元素的值也许不是0;
如果数组大小是常量,则数组初始化为0时,元素的值是0;
/**
当数组不是全局变量时:
如果数组大小是变量,则数组初始化为0时,元素的值也许不是0;
如果数组大小是常量,则数组初始化为0时,元素的值是0;
*/
#include <iostream>
using namespace std;
const int maxn=10;
int main()
{
cout << "数组大小是变量:\n";
cout << "输入两个值:\n";
int n, m;
cin >> n >> m;
int temp[n][m]={0};
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
cout << temp[i][j] << ' ';
cout << "\n数组大小是const 类型的常量:\n";
int matr[maxn][maxn]={0};
for(int i=0;i<maxn;++i)
for(int j=0;j<maxn;++j)
cout << matr[i][j] << ' ';
cout << "\n数组大小就是 common 常量:\n";
int a[10][10]={0};
for(int i=0;i<10;++i)
for(int j=0;j<10;++j)
cout << a[i][j] << ' ';
}
边栏推荐
- ClickHouse(03)ClickHouse怎么安装和部署
- 【问道】编译原理
- Ansible overview and module explanation (you just passed today, but yesterday came to your face)
- JS variable case output user name
- offer如何选择该考虑哪些因素
- Error: No named parameter with the name ‘foregroundColor‘
- Pointer and array are input in function to realize reverse order output
- What is Web3
- U++ 元数据说明符 学习笔记
- No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
猜你喜欢
【愚公系列】2022年7月 Go教学课程 005-变量
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
U++ game learning notes
Techniques d'utilisation de sublime
AOSP ~Binder 通信原理 (一) - 概要
一个酷酷的“幽灵”控制台工具
sublime使用技巧
A row of code r shows the table of Cox regression model
A line of R code draws the population pyramid
A simple and beautiful regression table is produced in one line of code~
随机推荐
STM32F103 realize IAP online upgrade application
Run the command once per second in Bash- Run command every second in Bash?
y58.第三章 Kubernetes从入门到精通 -- 持续集成与部署(三一)
Appium practice | make the test faster, more stable and more reliable (I): slice test
Servicemesh mainly solves three pain points
高数中值定理总结
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
STM32 encapsulates the one key configuration function of esp8266: realize the switching between AP mode and sta mode, and the creation of server and client
2. Overview of securities investment funds
精彩速递|腾讯云数据库6月刊
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str
装饰器基础学习02
基于Bevy游戏引擎和FPGA的双人游戏
STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
STM32 system timer flashing LED
Using thread class and runnable interface to realize the difference between multithreading
高手勿进!写给初中级程序员以及还在大学修炼的“准程序员”的成长秘籍
JS variable plus
A line of R code draws the population pyramid