为什么这个code可以运行?双一[3];一个[1,1] = 1; [英] why this code can run ? double a[3]; a[1,1]=1;

查看:94
本文介绍了为什么这个code可以运行?双一[3];一个[1,1] = 1;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()
{
    double a[3];  
    a[1,1]=1;
}

有通vs2013编译器,并且它不是二维阵列

It passes the vs2013 compiler, and it is not 2D array.

推荐答案

您调用的逗号操作符。这种评估其第一个操作数,将其丢弃,并返回第二个。所以,你的code是相当于

You are invoking the comma operator. This evaluates its first operand, discards it, and returns the second one. So your code is the equivalent of

a[1] = 1;

用于访问二维阵列的元素的语法将是

The syntax for accessing an element of a 2D array would be

b[1][2] = 42;

这篇关于为什么这个code可以运行?双一[3];一个[1,1] = 1;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆