1. 程式人生 > >C學習筆記(二)-理論

C學習筆記(二)-理論

C學習筆記(二)-理論


本部落格用來記錄理論易錯題及一些重點概念。
如存在問題,歡迎指出。

理論選擇易錯題

  1. What is the output of this C code?

    #include <stdio.h>
    	int main(){
    	int i = j =10;
    	printf("%d\n", j++);
    	return 0;
    }
    

    Ans: Compilation error: Use of undeclared identifier ‘j’

  2. What is the output of this C code?

    #include <stdio.h>
       int main(){
       int i =0, j =0;
       if(i &&(j = i +10)); //!!!
       		printf(%d”,j);
       return 0;
    }
    

    Output: 0

  3. What is the output of this C code?

    #include <stdio.h>
    int main(){
    	float x =0.1;
     	printf("%d, ", x);
    	printf("%f", x);
    	return 0;
    }
    

    Ans: Junk value, 0.100000

  4. What is the output of this C code?

    #include <stdio.h>
    int main(){
      float x = 10;
      if (x < 5)
        printf("x < 5");
      else if (x > 10)
        printf("x > 10");
      else
        printf("Unknown");
    
      return 0;
    }
    

    Ans: Unknown

  5. What is the output of the code given below?

    #include <stdio.h>
    int k = 0; void display(){ printf("%d ",k++); //main裡的k未傳入 } int main(){ int i; static int k = 10; for (i = 0; i < 5; i++) display (); printf("\n"); return 0; }

    Ans: 0 1 2 3 4

  6. What is the output of this C code?

    #include <stdio.h>
    int main(){
    	extern int x;
    	int x = 0;
    	printf("%d",x);
    	return 0;
    }
    int x = 100;
    

    Ans: compile-time error: Non-extern declaration of ‘x’ follows extern declaration

  7. Computer can execute the code in ____.
    Ans: machine language

  8. ___ translates high-level language program into machine language program.
    Ans: A compiler(編譯程式)