KembaraXtra - Computer Science: Comments in Programming Languages - A Study Guide
What are Comments?
Definition: Text added to source code to explain or provide context about the code.
Purpose:
• Improve code readability for other developers (or your future self).
• Explain the logic behind complex code sections.
• Provide usage examples.
• Document code functionality.
Impact on Execution: Comments are ignored by the compiler/interpreter. They do not affect how the program runs.
C-Style Comments
Multiline Comments:
• Syntax: Enclosed within /* and */
• Example: /*
This is a C-style comment.
It can span multiple lines.
*/
Single-Line Comments:
• Syntax: Begins with //
• Note: Originally introduced in C++ and later adopted by C.
• Example: // This is a single-line C comment.
Python Comments
Single-Line Comments:
• Syntax: Begins with #
• Example: # This is a comment in Python.
Multiline Comments:
• No Dedicated Syntax: Python doesn't have a built-in multiline comment syntax.
• Workaround: Use multiple single-line comments. # This is the first line of a multiline comment.
# This is the second line.
# And this is the third line.
0 Comments
Author
Write something about yourself. No need to be fancy, just an overview.