單行註釋 // (single line comment)

註釋是用來告知自己或他人有關程式的運作方式。編譯時會忽略,而不會載入到處理器內執行,所以註釋不佔用的Atmega晶片上的記憶體空間。

註釋重要的目的是幫助你理解(或記住..),您的程式如何運作,尤其是隔了一段時間再開啟自己寫過的程式。還有是告知他人您的程式是如何工作的。有兩種不同的註釋的方法:(單行與多行)

單行註釋範例:

x = 5;  // This is a single line comment. Anything after the slashes is a comment

// to the end of the line

多行註釋範例:

/* this is multiline comment – use it to comment out whole blocks of code

 

if (gwb == 0){   // single line comment is OK inside a multiline comment

x = 3;           /* but not another multiline comment – this is invalid */

}

// don’t forget the “closing" comment – they have to be balanced!

*/

 

提示:

在程式發展過程或除錯時,“註釋掉”你的程式的一部分是一種便利的方法。因為註釋後的程式碼暫不執行,所以編譯器根本不會理它們。試圖找到一個問題時,這一點特別有用。 另一個優點,當除錯的問題解決後,刪掉註釋符號,可以快速回復程式碼,不須重新輸入。

Reference Home