我正在尝试用随机整数填充我的2D数组。
//rows, cols are randomly generated ints between 1 and 10
int rows = rand()%10 +1;
int cols = rand()%10 +1;
int arr[rows][cols];
for (i = 0; i <rows; i++){
for (j=0; i<cols; j++){
arr[i][j] = rand()%10;
}}
每次我尝试运行此代码时,都会给我一个分段默认值。
我编辑了帖子以提供我正在运行的实际代码
答案 0 :(得分:4)
我想这是因为i < ...
j < ...
中for (j=0; i<cols; j++)
应该是@IBAction func faceURL(_ sender: Any) {
if let facebookURL = URL(string: "https://www.facebook.com")
{
UIApplication.shared.openURL(facebookURL) // the open method you were using doesn't exist in Swift
}
}
;