Computer Science

Comments in C

Comments in C are non-executable text that provide explanations or notes within the code. They are used to improve code readability and understanding for developers. Comments are ignored by the compiler and do not affect the program's functionality, making them a useful tool for documenting code and communicating with other developers.

Written by Perlego with AI-assistance

3 Key excerpts on "Comments in C"

Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.
  • PLC Controls with Structured Text (ST)
    eBook - ePub

    PLC Controls with Structured Text (ST)

    IEC 61131-3 and best practice ST programming

    ...3 Comments in programming code Comments are a very important part of programming. Comments in the programming code assist you and your colleague when later adding in the code. Use comments to explain what a specific PLC code performs, so you can remember it later yourself. In many cases, the PLC code can be self-explanatory, therefore it is a better choice only to make comments when coding is complex. There are two types of comments in ST: Line Comment // Line comment. Forward-slash is written in front of EVERY line. // Also used to remove/sort out PLC code – i.e. a code which is not executed // The code has disappeared if it is deleted, therefore place // in front of the line // instead of deleting the code by placing // in front of the code, the code is still to // be seen but not executed Block Comment (* Block comment is initiated by start parentheses and a star. It is finalized by a star and end parentheses. They are used for making more lines of PLC code inactive *) Line comments can be only be positioned on the same line in front of or after code. Comments positioned between (* and *) are named block comments and are used in order to remove/sort out more lines of code or to write comments filling up more lines. For every program module or function comments at the top lines are used so that another programmer quickly can read a description or introduction to the program module or the function. It is recommended that the top lines contain a version log so it is possible to recognize what has currently been changed in the PLC code and by whom: //////////////////////////////////////////////////////////////////////////////////////////// /// OP002 Parking house /////////////////////////////////////////////////////////////////////////////////////////// // Action for each connected sensor // //************************************************* // Version 1.0, Created...

  • The SAGE Encyclopedia of Educational Research, Measurement, and Evaluation

    ...A variant of this common code is presented in Figure 1. The first line begins with code comments placed between /* and */ to denote the beginning and end of a comment, respectively. Text between these two placeholders can span multiple lines. The importance of commenting code cannot be emphasized enough, especially if code is shared with others or is to be revisited at a later date. Figure 1 Example of C programming code The code example continues with an # include preprocessor directive to tell the C compiler that the functions in the standard input/output header file (<stdio.h>) should be made available for the subsequent code to use. The third line begins the declaration of the main function, which returns an integer data type as the output. The void given to the function is not required technically but is shown here to illustrate an assumption that the compiler would otherwise make. The code within the function is indented for readability purposes. This is a very useful practice in programming because C compilers ignore such spacing. Within the curly braces on Line 5 of Figure 1, the printf function is used to send formatted output to the terminal window. The content inside the double quotes gets printed on the screen. Inside of the quotes, any character that immediately follows a backslash (the combination of which is known as an escape sequence) is ignored, so that the compiler can receive additional instructions. The \ n tells the compiler to create a line break. The end of the statement ends with a semicolon, as all expression or declaration statements should. However, preprocessor directives (i.e., #include) and control structures (i.e., loops and conditional logic) do not require a semicolon, as evidenced in the example code. Finally, Line 6 returns the integer zero to the terminal to indicate that the program executed correctly...

  • Using LEDs, LCDs and GLCDs in Microcontroller Projects
    • Dogan Ibrahim(Author)
    • 2012(Publication Date)
    • Wiley
      (Publisher)

    ...Imagine how hard it would be to write a complex program with no comments and then try to modify the program after several months. All the comment lines are ignored by the compiler. In mikroC Pro for PIC language, comments can be of two types: long comments and short comments. Long comments start with the character pair: and end with the character pair: Long comments are commonly used at the beginning of a program to describe the program details, such as what the program does, what type of hardware is used, who the author is, the date program was created, filename of the program, version history, and so on. You can see the use of long comments at the beginning of our simple program. Long comments are also used inside a program to describe the operation of part of the program, for example the parameters of functions, the algorithm used, and so on. Short comments start with the character pair: Short comments are not terminated with a character and they can be used in a single line, starting anywhere in the line. These comments are generally used after program statements and they describe what the statement does. Examples of short comments can be seen in our simple program in Figure 3.1. 3.2.2 Beginning and Ending a Program In mikroC Pro for PIC language, a program starts with the keywords: After this, a curly opening bracket is used to indicate the start of program body. The program is terminated with a curly closing bracket. Thus, the structure of a program is (see Figure 3.1): The program body consists of program statements. Each program statement must be terminated with a semicolon (‘;’) character to indicate the end of the statement, otherwise an error will be generated by the compiler: 3.2.3 White Spaces White spaces in programs consist of spaces, tabs, newline characters, and blanks. These characters are ignored by the compiler...