Bifalgorithm post · Computer science one · Comments

How are comments written and used in a C program?

How are comments written and used in a C program? (Computer science one · Comments) — "Comments can be written in a C program either as a single line using two…

Ideas in this flowchart

  • Comments in a C program
  • Single-line comments begin with //.
  • Everything after // on the same line is ignored.
  • Multiline comments begin with /* and end with */.
  • Everything between /* and */ is ignored, including line breaks.
  • The compiler ignores comments, so their quantity does not affect the final executable code.
  • Examples of comments
  • A standalone single-line comment: //this is a single line comment
  • A single-line comment can follow code: int x; //this is also a single line comment
  • A multiline comment can span several lines to format its message clearly.
  • Most code editors and IDEs use a special color or font to distinguish comments from code.
  • A multiline comment must be closed properly.
Feed/

How are comments written and used in a C program?

No cover

Channel

Computer science one

1 page

"Comments can be written in a C program either as a single line using two forward slashes, //comment or as a multiline comment using a combination of forward slash and asterisk: /* comment */. With a single line comment, everything on the line after the forward slashes is ignored. With a multiline comment, everything between the forward slash/asterisk is ignored. Comments are ultimately ignored by the compiler so the amount of comments do not have an effect on the final executable code. Consider the following example.\n\n1 //this is a single line comment\n\n2 int x; //this is also a single line comment, but after some code\n\n3\n\n4 /*\n\n5 This is a comment that can\n\n6 span multiple lines to format the comment\n\n7 message more clearly\n\n8 */\n\n9 double y;\n\nMost code editors and IDEs will present comments in a special color or font to distinguish them from the rest of the code (just as our example above does). Failure to close a"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.