- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Errors In C++

Posted by Tayyab



"ERRORS"

What is Syntax Error in C / C++ porgramming language?

Answer: What is syntax errors in c c++ programming language? Syntax Errors: A collection of the rules for writing programs in a programming language is know as syntax. All program statements are written according do these rules. Syntax error is a type of error that occurs when a invalid statement is written in program. The compiler detects syntax errors and display error massage to describe the cause of error. A program containing syntax errors can`t be compiled successfully.

These can be many causes of syntax error some important causes are as follows:
  • The statement terminator is missing at the end of statement like coma, semicolon ( ); etc.
  • A misspelled keyword is used in the program.
  • Any of the delimiters is missing.
Example: Typing "forr" insted of "for" is an example of syntax error.

What is Logical Error in C / C++ porgramming language?


Answer: These errors solely depend on the logical thinking of the programmer and are easy to detect if we follow the line of execution and determine why the program takes that path of execution and it is also called Runtime Error.
Listed below are some common programming errors
1. Misuse of the Include Guard.
A common mistake is to use same symbol in multiple files for #ifndef.
2. Typo's : Using ">" for ">>" and "<" for "<<"
3. Trying to directly access the private variables in the main program.
4. Switch Statments without break.
5. Wrong usage of postfix and prefix operator (diff between i++ and ++i)
6. Undeclared and Unitialised Variables and functions.
7. ALWAYS USE MAKE FILE if you have more than one C++ program. The order of compilations matters a lot too.
8. Trying to include "INCORRECT" header fuction.
9. Marking a member function as const in the class definition but not in the member function implementation. 
10. Returning a value in a void function. 
11. Confusing the name of an array with the contents of the first element. 
12. Cstring array Errors - Arr[10] = Arr[0] to Arr[9]. Trying to access Arr[10] element.
13. Using "=" ( assignment operator ) instead of "= =" (comparison operators) scanf() without '&' and wrong format.(IN C)
14. Trying to divide a number by Zero.
15. Poor Loop Exiting comparisons will tend to either loop being not executed at all or goes to an infinite loop.
16. Not using string functions and treating the strings are integer . Say trying to compare string by (string1= = string2) , rather than using strcmp command
17. CString not terminated by '\0'- Null character
18. Mismatched "{" or IF-ELSE statements or for that matter any looping statment.

What is Runtime Error in C / C++ porgramming language?

Run-Time Errors

Run-time errors only occur when you run a program, and thus, they can only occur if there is a program to run (i.e., it must have compiled and linked without errors). When you run the executable and something goes wrong then we call it a run-time error. There are two main types of run-time errors:
  1.  Fatal Errorsfatal error is basically when the executable crashes.
    Example 1: The program divided by zero, as in:
    int scores = 500;
    int num = 0;
    int avg;
    avg = scores / num;
    
    The program would crash saying:
    Floating exception
    
    Example 2: Segmentation faults, Bus errors.
    These occur when you try to access memory that your program is not allowed to use or that doesn't exist in the computer (i.e., there is only so much memory in the computer).


    Aside: Even virtual memory has limits.
    Your program will crash giving the "Segmentation fault" or "Bus error" message.
    These errors often occur due to improper use of arrays or pointers.
    Example: Using an uninitialized array index...
    int values[10];
    int i;
    cout << "The ith value is: " << values[i] << endl;
    
    may cause such an error. These, particularly, are tricky since they may or may not occur based on what the initial garbage value of the index is when you run the program. Remember, you cannot generally assume variables get initialized to zero.
  2.  Logic Errorslogic error occurs when your program simply doesn't do what you want it to.
    Example: You have an infinite loop because you did not update the variable(s) used in the condition of a loop, as in:
    cin >> account_num;
    
    Assume user did not enter -1.
    
    while (account_num != -1) {
      cout << "Account #: " << account_num << endl;
      ProcessAccount(account_num);
      // Oops...Forgot to read another account # here!
    }
    

There are two general techniques for finding the cause of a run-time error:
  • Narrow down where in the program the error occurs.
  • Get more information about what is happening in the program.
Both techniques can be applied either with or without a debugging utility.

What is Execution Error in C / C++ porgramming language?

Execution error 
These errors occur at the time of execution. Looping and arithmetic errors falls under this category.


What is Linker Error in C / C++ porgramming language?


Linker error 
These are errors generated when the executable of the program cannot be generated. This may be due to wrong function prototyping, incorrect header files.


0 comments:

Post a Comment