小编Sri*_*adh的帖子

为什么这个数组分配给非指定数组?

/*我观察到的是:

  1. 当我给b(数组)提供类似"ab"的字符串时
    输出为:"ab""help""dude"
  2. 当我给"abc"
    然后输出是:"abc""""dude"
  3. 如果我给"abcd",那么输出是:"abc""d""dude"

    等等*/

       #include<stdio.h>
       main()
       {
            char a[5]="help",b[3],c[10]="dude";
         scanf("%s",b);
         printf("\t%s",b); 
         printf("\t%s",a);
         printf("\t%s",c);
       }
    
       /* what i dont get is :
        Here iam  gaving a string to b(array),  why, if the string has more than the  
        required no. of charecters, its printing those charecters in other arrays 
       (though i had not assiged scanf to other arrays )?   
    
    Run Code Online (Sandbox Code Playgroud)

c c++ arrays undefined-behavior

1
推荐指数
1
解决办法
93
查看次数

为什么printf不在这里打印?

我知道执行后的printf返回一些非零值{编辑:返回否.charecters}现在在这个例子中我使用了多个printf和现在.

 /* As far as i was cocerned Precedence of && is more than ||,
  *and these logical operators check from left to right  
  *So compiler should come to hello and print "hello" then "nice to see you" then "hie" 
  *as all are true it should print "hola" 
  *but i wonder, why here the output is only "hie" and "hola"?
  */  

 #include<stdio.h>
 main()
 {
    if(printf("hie")|| printf("hello")&& printf("nice to see you"))
    printf("\thola\n");
 }
Run Code Online (Sandbox Code Playgroud)

c c++ printf

-2
推荐指数
1
解决办法
171
查看次数

标签 统计

c ×2

c++ ×2

arrays ×1

printf ×1

undefined-behavior ×1