Breaking News

Understand the types of Error and Comment in Programming


Error is a bug that cause a program to misbehave or operate incorrectly. This is the normal thing to those who are beginners in any programming language so when you face it for the first time don't panic just stay down and sketch the flow of your code so as to fix it.

There are three main types of Errors.
  1. Syntax Error: This is the type of error caused by misconstruction of syntax (rules). When this type of error occur, it cause the program to stop running, and it can be discovered during compiling process. Example declaration of variable as int 6_num; When we learnt the rules of creating a variable in previous post, we said that variable name can't start with number, so this declaration cause Syntax Error.
  2. Logic or Semantic Error: This is the type of error that caused by bad writing of logic in your source code. It can't be seen during compiling process but after running your program it can be discovered. This type of error is the one that create unexpected output of your program. Example: When we take 4 + 6 we expect the output to be 10 but when this error comes to your program can produce any number such that 4 + 6 = 81. So again you can fix this error by sketching the flow of your program very well.
  3. Runtime Error: This is the type of error cause by bad writing of logic in your program. This type of error can occur when you run your program before it start to execute while the syntax of your program is correct.
Before applying those concepts in compiler, let us finalize this term known as Comment. Any Programming language should have something called comment.
Comment is the line(s) that is ignored during the compiling or execution of your program. This is placed so as to provide some description of your source codes, as we know you can develop a large software, and during your lifetime someone may come to continue the development that started by you or can edit something on it or even fixing an error while you are not there, so as to help her/him you have to provide some descriptions to your source code such that "This lines of code is for making user login" so when somebody see this comment can understand that whenever I need to fix or change anything concerned with user login I have to look through these lines of codes only and not other place.

In C++, comments can be written in two (2) ways:
  1. Single Line Comment: This can be used only when you need to comment a single line, and it takes the sign of ( // ). Example: //This comment can work only in a single line...
  2. Multiline Comment: This can be used only when you need to comment on more than one lines of code, and it takes the sign of ( /*.......*/). Example: /*This one line has been commented...... This second line has been commented......This third line has been commented......*/

No comments