Q37. What is the difference between run-time error and syntax error? Give one example of each.
Ans. A compiler can report syntax error, while run-time error become known at run-time and can be detected by tracing the program line by line.
Syntax Errors occurs when rules of a programming language are violated.
For instance, in the following program segment,
int a, b:
cout<<a + b,
The first statement of main() produces a syntax error as the statement is terminated by : rather than ;. The third statement also has the similar error, it is terminated by, rather than ; and the last statement also has missing (;), again an error.
Run-time Errors (Execution Error) occurs during the execution of a program. It is caused of some illegal operation taking place or inavailability of desired or required conditions for the execution of the program.
For instance, is a program is trying to open a file which does not exist or it could not be opened, it results into an execution error.