当前位置:网站首页>局部变量的数组初始化问题
局部变量的数组初始化问题
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] << ' ';
}
边栏推荐
- 3. Type of fund
- JS variable plus
- 【最佳网页宽度及其实现】「建议收藏」
- Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
- Monitoring cannot be started after Oracle modifies the computer name
- torch optimizer小解析
- Canteen user dish relationship system (C language course design)
- PLC Analog output analog output FB analog2nda (Mitsubishi FX3U)
- Error: No named parameter with the name ‘foregroundColor‘
- Leetcode notes
猜你喜欢
Basic knowledge of road loss of 3GPP channel model
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
【opencv】图像形态学操作-opencv标记不同连通域的位置
[736. LISP syntax parsing]
【愚公系列】2022年7月 Go教学课程 005-变量
Weebly移动端网站编辑器 手机浏览新时代
深入解析Kubebuilder
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
Ansible overview and module explanation (you just passed today, but yesterday came to your face)
Why do many people misunderstand technical debt
随机推荐
Clickhouse (03) how to install and deploy Clickhouse
National meteorological data / rainfall distribution data / solar radiation data /npp net primary productivity data / vegetation coverage data
U++4 接口 学习笔记
U++ game learning notes
2.证券投资基金的概述
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
U++4 interface learning notes
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
Talk about the importance of making it clear
STM32F103 realize IAP online upgrade application
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails
Understand common network i/o models
JS also exports Excel
Time complexity & space complexity
第一篇论文的写作流程
Analysis -- MySQL statement execution process & MySQL architecture
[Yugong series] go teaching course 005 variables in July 2022
JS input and output
深入解析Kubebuilder
offer如何选择该考虑哪些因素