| 1. |
Differentiate between i. Static variables and auto variables. ii. Execution error and compilation error. |
|
Answer» (i) Static variables and auto variables: Static variables: The features are as follows Declaration place:-may be declared internally or externally. Declaration syntax:-we use the keyword static to declare a static variable. Static int age; Default initial value:- Zero Scope:-in case of internal static variable, the scope is local to the function in which defined while scope of external static variable is to all the functions defined in the program. Life:- value of variable persists between different function calls. Automatic variables: The features are as follows Declaration place:-declared inside a function in which they are to be utilized, that’s why referred as local or internal variables. Declaration syntax:- A variable declared inside a function without storage class specification by default is an automatic variable. However, we may use the keyword auto to declare it explicitly. main() { auto int age; } Default initial value:-Garbage value Scope:-created when the function is called and destroyed on exit from the function. Life:- till the control remains within the block in which defined. (ii) Execution error and compilation error: Errors such as mismatch of data types or array out of bound error are known as execution errors or runtime errors. These errors are generally go undetected by the compiler so programs with run-time error will run but produce erroneous results. Compilation error also known as syntax errors are caused by violation of the grammar rules of the language. The compiler detects, isolate these errors and terminate the source program after listing the errors. |
|