C Programming Tutorial 16 - Comments

submitted by mkenny400 on 03/19/18 1

This video is going to introduce you to the concept of comments. In general, comments are pretty easy to understand. I'm going to try not to waste your time by giving you some extra information relating to comments that may come in useful for you when you work on bigger projects. To do a single line comment, use // Anything after that will be ignored. The comment allows you to put whatever you want and the compiler does not care if it is here. Run the program and see that it does exactly the same thing. A multiple line comment allows you to put comments as long as you want and it will continue to the next line… /*This is a multiple line comment */ These are useful for when you want to make a block comment that is usually used for describing a program or something: /************************************ Author: Caleb Curry Description: Calculates how many dozen eggs Date: 03/17/2017 ************************************/ These actually do not have to be on multiple lines. I'll show you an example where these comments might come in handy. We haven't discussed if statements, but here is a sneak peak of what is going to be coming up in the future. You can see that I was able to throw a comment in the code and then continue coding on the same line. Run this and see that it does exactly what you expect it do. Now, a lot of people use comments to describe what some confusing code does. It's super important though that you always keep comments up to date. Nothing is more confusing than reading a comment that says code does something when it really does something else. When should you comment? Well, if you see any kind of confusing math or confusing syntax, leave a comment before it to explain it. Imagine you are going to read it in 5 years and you want to know what it is doing. When there is some piece of code you need to remember to implement or something you need to remember to fix, you can start the comment with TODO. That way, when you are finishing up your software you can do a search for TODO. To search in vim all you have to do is type / followed by the word you are searching for: /eggs Then press n to go to the next value of it. When to not comment? Don't comment on anything that is obvious. Often in college they want students to leave a comment on everything. Personally, I think this is a bad thing to teach students as it teaches them to over comment on things that should be clear from the code itself, but whateverrrrrrrr. Honestly, I would avoid using large comment blocks at the top of a program when possible. I think the only thing you should really write at the top is the purpose of the program. You can put them for now, but once you start working on more sophisticated software, you are going to use a software such as Git which is going to keep track of all dates and people anyways, so it's a waste of effort and just another thing that can be wrong. For example, you might get hired at a company and all of their code has the author of the previous guy who worked there who got moved to a new department. Are you supposed to change it to you? Add your name? It just introduces confusion. This video I taught you about comments, but I also touched on how to search in vim. Vim might not be so crappy if we actually knew how to use it a bit. So in the next video we are going to learn some ways to make Vim a little bit more user friendly. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×