1. 程式人生 > >C programming tutorial 筆記

C programming tutorial 筆記

lin std sha tput ger style scope watch data

tutorial 3


使用linux系統運行c,

安裝gcc,為compiler,使用vim等工具寫好hello world程序,命名hello.c

#include <stdio.h>

int main(){  //int means the returned data type
  printf("hello world!\n"); // \n means a new line
  return 0; //the program worked as expected  
}

之後在terminal中輸入:gcc hello.c,之後會自動生成a.out文件,然後輸入 ./a.out 運行

tutorial 10


#include <stdio.h>
int main(){
  int x = 10;
  int y = x/2;
        
  printf("the magic number is: %i\n",y);    //"", is a format string, and %i inside means it‘s an integer, \n is new line, y is the variable you want to print
  printf("the magic number is: %i\nThe value x is: %i\n",y,x);//this will work too, first string,y and x are arguments
  
 return 0;      
}//the first output is 5;

  

  

參考內容:


C Programming Tutorials

C programming tutorial 筆記