在C中,如果我没记错的话,您可以使用花括号语法轻松初始化数组:
int* a = new int[] { 1, 2, 3, 4 };
Run Code Online (Sandbox Code Playgroud)
当您希望初始化具有特定测试值的矩阵用于数学目的时,如何在Fortran中对二维数组执行相同的操作?(无需对单独的语句中的每个元素进行双重索引)
该数组由.定义
real, dimension(3, 3) :: a
Run Code Online (Sandbox Code Playgroud)
要么
real, dimension(:), allocatable :: a
Run Code Online (Sandbox Code Playgroud)