Niuke [c language practice]

multiple choice

  1. The output of the code snippet below is (-12)
int main() {
    
    
    int a=3; 
    printf("%d\n",(a+=a-=a*a)); 
} 
	a+=a-=9,此时还是等于3,因为a*a只是运算,并没有赋值;
	之后再算a-=9,运算之前a等于3,运算完之后此时a等于-6;
	再算a+=-6,a+=a为-6+(-6)结果为-12
  1. The output of the code snippet below is (3 5 3)
int a=3,b=5,c=7;
if(a>b) a=b; c=a;
if(c!=a) c=b;
printf("%d,%d,%d\n", a, b, c);
if (a>b) a=b; c=a;在这一语句当中a=b后面用的是分号,所以当if成立时,只会执行a=b,
而之后的c=a虽然写在同一行,但会被视为两行语句,并不和if判断逻辑挂钩。也就是说,即使if不成立,c=a同样会执行。

3. In C language, when a simple variable is used as an actual parameter, the data transfer method between it and the corresponding formal parameter is ( )

A  地址传递
B  单向值传递

简单变量作为实参时,将把该变量所占内存单元的值传递给形参,实参和形参各占不同的内存单元,传递完后,实参和形参不再有任何联系,所以这种传递方式也叫做单向值传递方式。所以正确答案是B。
  1. If the following program
#include<stdio.h>
int f (char x){
    
    
    return x*x%10;
}
main(){
    
    
    char a; 
    int b=0;
    for (a=0; a<5; a+=1){
    
    
        b =f(a);
        printf("%d",b);
    }
}
a=0 
b=f(0)
return 0*0%10=0

a=1
b=f(1)
return 1*1%10=1

a=2 
b=f(2)
return 2*2%10=4

a=3 
b=f(3)
return 3*3%10=9

a=4 
b=f(4)
return 4*4%10=6
  1. It is known that year is an integer variable, and the expression (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 cannot make the value of "true" data is (A)

     A1990
     B1992
     C1996
     D2000
    
     程序翻译一下就是 四年一闰 百年不闰 四百年补闰   
      		A 1990%4=2(!0)不是闰年   
     		B 1992%4==0(0)是闰年 
      		C 1996%4==0(0)是闰年 
       		D 2000%4==0(0)&&2000%400==0(0)是闰年
    
  2. The result of running the following program segment is (xyz)

char s[6] = {
    
    'x','y','z','\0','1','2'};
puts(s);
 '\0'空字符是字符串的终止符。 
 puts(s)表示把一个字符串写入到标准输出 stdout,直到空字符,但不包括空字符。
  1. The following statement is wrong ()

a = b+c = 3; //是错的
//
涉及到一组概念叫 左值 右值  b+c 是个右值,右值不能被赋值。  ```

Guess you like

Origin blog.csdn.net/becomeyee/article/details/131022616