When we write code it is important to document the code’s behavior. One way to do this is to add comments to our code.

Starting a line with a double forward slash, //, will create a comment and the entire line will be ignored when we run the code.

// This is a single line comment // This is 2 single line comments // together to explain a little more

The comments like the ones above can be added above a line or block of code to describe the code’s behavior. Shorter comments can be added to the end of a line of code as well.

printf("My dog is happy!"); // How my dog feels

In both examples, once you use // the rest of the line is now a comment.

If you want to create a comment with a beginning and end, you can use /* to begin the comment and */ to end the comment. This is known as a block comment:

/* The following output will be an outburst from my dog in a moment of pure joy after seeing another dog across the street. */ printf("Woof!");

As you can see from the above example a block comment can wrap multiple lines without the use of anything but the beginning notation /* and the ending notation */.



The code in script.c is outputting a couple lines of text. Make sure you notate your thoughts above each string being output.

Above the first printf() statement in main():

  • Add a single line comment with your own message about the string that’s output

Now give yourself some more room for commenting your code.

Above the second printf() statement inside main():

  • Add a block comment with your extended thoughts on this string

While your additions to the code do not change the output, you have now recorded your thoughts on the code which might come in handy when you revisit the code another time.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?