不明白这个开关以及输出的原因

时间:2016-03-10 03:02:25

标签: c

我不明白为什么输出只是沃伦。转换(金钱,金钱* 2)意味着什么?

#include<stdio.h>
#define L 10
void main(){
     auto money=10;
     switch(money,money*2){
        case L: printf("William");
               break;
        case L*2: printf("Warren");
               break;
        case L*3: printf("Carlos");
               break;
        case L*4: printf("Inqvar");
               break;
        default: printf("Lawrence");
     }
}

2 个答案:

答案 0 :(得分:2)

在这种情况下,

switch(money, money*2)switch(money*2)一样好,因为money之前的第一个表达式,没有做任何事情。

答案 1 :(得分:0)

简答:评估第一个表达式1,然后计算表达式2.但是返回表达式2的值。所以这基本上相当于:

 public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('firstname');
            $table->string('lastname');
            $table->text('slug');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->decimal('fidbonus', 6, 2);
            $table->rememberToken();
            $table->timestamps();
        });
        Schema::create('Userinfos', function (Blueprint $table) {
           $table->increments('id');
           $table->integer('User_id')->unsigned();
           $table->foreign('User_id')->references('id')->on('Users');
           $table->string('address');
           $table->string('address2');
           $table->text('city');
           $table->string('zip');
           $table->string('country');
           $table->string('Phone');
           $table->timestamps();
       });
       Schema::create('password_resets', function (Blueprint $table) {
           $table->string('email')->index();
           $table->string('token')->index();
           $table->timestamp('created_at');
       });
    }

长答案:这是What does the comma operator , do in C?

的副本