当前位置:网站首页>局部变量的数组初始化问题
局部变量的数组初始化问题
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] << ' ';
}
边栏推荐
- 【736. Lisp 语法解析】
- U++ metadata specifier learning notes
- Mysql database (basic)
- torch optimizer小解析
- JS variable case
- 腾讯云数据库公有云市场稳居TOP 2!
- 为什么很多人对技术债务产生误解
- Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
- A row of code r shows the table of Cox regression model
- The sooner you understand the four rules of life, the more blessed you will be
猜你喜欢
随机推荐
JS input and output
Error: No named parameter with the name ‘foregroundColor‘
5G VoNR+之IMS Data Channel概念
torch optimizer小解析
ThinkPHP关联预载入with
Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
01 machine learning related regulations
Inventory host list in ansible (I wish you countless flowers and romance)
Stm32f103ze+sht30 detection of ambient temperature and humidity (IIC simulation sequence)
【PHP SPL笔记】
使用Thread类和Runnable接口实现多线程的区别
U++4 接口 学习笔记
腾讯云数据库公有云市场稳居TOP 2!
记录一次压测经验总结
Using thread class and runnable interface to realize the difference between multithreading
AOSP ~Binder 通信原理 (一) - 概要
【opencv】图像形态学操作-opencv标记不同连通域的位置
app内嵌h5---iphone软键盘遮挡输入文字
谈谈讲清楚这件事的重要性
Weebly mobile website editor mobile browsing New Era