Common Header Files & their Member Functions
main( ) function
Importance of main: main() function is the first function to be executed in the program. All the remaining functions in the program are either called from main() or from the functions, which are called by main function.
Types of Errors
Run-time error: A run-time error occurs during the execution of the program, when the program performs an illegal/unexpected operation.
Example: int a, b, c; cin>>a>>b; c = a/b;
This code will result in Run-time error if b is entered as 0
Syntax Error: A syntax error occurs when the compiler is unable to translate the program to machine language due to violation of rules of the programming language.
Example: int a, b, c (missing a semi-colon)
This code will not compile since it’s having a Syntax error
Logical Error: A logical error occurs when the program contains wrong formula or wrong calculation, which may be syntactically correct. The program having logical errors may give some output but not the expected one.
Example: Calculate Average avg = n1 + n2 + n3/3;
This code will result in the wrong output (average)
Types of Variables
Global Variable: A variable which is declared outside all the functions in the program, is known as global variable. A global variable can be accessed and modified in any part of the program (i.e. in any function). If local variable carries identical name as global variable, to access the global variable scope resolution operator (::) is required.
Local Variable: A variable which is declared inside a function or a compound statement in the program is known as local variable. A local variable can be accessed and modified in the function or the compound statement (code block) in which it is declared but not outside its function/code block.