Q. Distinguish between the following:
(i) Syntactic error and semantic error
(ii) Run time error and logical error
(iii) Compiler and Interpreter


Ans:(i)Syntactic error and semantic error
Syntactic errors also known as compilation errors are caused by violation of the grammar rules of the language. The compiler detects, isolate these errors and give terminate the source program after listing the errors. Some of the common syntactic errors are:
• missing or misplaced ; or }
• missing return type for a procedure
• missing or duplicate variable declaration

Semantic errors are logical errors. If there is a semantic error in a program, it will run successfully, in the sense that the computer will not generate any error messages, but it will not do the right thing. The problem is that the meaning of the program (its semantics) is wrong. Identifying semantic errors can be tricky because it requires working backward by looking at the output of the program and trying to figure out what it is doing.

(ii) Run time error and logical error
Run-time errors: Errors such as mismatch of data types or array out of bound error are known as runtime errors. These errors are generally go undetected by the compiler so programs with run-time error will run but produce erroneous results. Logical errors: These are the errors related with the logic of the program execution. These errors are not detected by the compiler and are primarily due to a poor understanding of the problem or a lack of clarity of hierarchy of operators. Such errors cause incorrect result.

(iii) Compiler and Interpreter
These are two types of language translators.
A compiler converts the source program (user-written program) into an object code (machine language by checking the entire program before execution. If the program is error free, object program is created and loaded into memory for execution. A compiler produces an error list of the program in one go and all have to be taken care even before the execution of first statement begin. It takes less time for execution.

An interpreter is also a language translator that translates and executes statements in the program one by one. It work on one statement at a time and if error free, executes the instruction before going to second instruction. Debugging is simpler in interpreter as it is done in stages. An interpreter takes more time for execution of a program as compared to a compiler.

(VI) Latent errors: These are hidden errors which come into the picture only when a particular data set is used. For example, consider the following statement:
int z=x/x-y;
An error will occur when x and y are equal.

Q.  What are the qualities and capabilities of good algorithms?

Ans: Every algorithm should have the following five capabilities and qualities:

1.Input: The algorithm should take zero or more input.
2. Output: The algorithm should produce one or more outputs.
3. Definiteness: Each and every step of algorithm should be defined unambiguously.
4. Effectiveness: A human should be able to calculate the values involved in the procedure of the algorithm using paper and pencil.
5. Termination: An algorithm must terminate after a finite number of steps.

Q. What are the features of C preprocessor? Give the differences between macros and functions?

Ans: A pre-processor is a program that processes the source code before it passes through the compiler. It operates under the control of preprocessor directive. These are placed in the source program before the main.
To define a macro, # define statement is used. This statement, also known as macro definition takes the following general form:
#define identifier string

The pre-processor replaces every occurrence of the identifier in the source code by the string. The preprocessor directive definition is not terminated by a semicolon. For example #define COUNT 100 will replace all occurrences of COUNT with 100 in the whole program before compilation. Similarly we can define small functions with the help of macros.

For example, a macro defined as
#define SQUARE(x) (x*x) will calculate square of argument when it is called. This is called macro definition.

macro definition.
Macros Vs Functions:
A macro's definition is expanded into the code each time the macro is encountered in the source code. If your program invokes a macro 100 times, 100 copies of the expanded macro code are in the final program. In contrast, a function's code exists only as a single copy. Therefore, in terms of program size, the better choice is a true function.
When a program calls a function, a certain amount of processing overhead is required in order to pass execution to the function code and then return execution to the calling program. There is no processing overhead in "calling" a macro. In terms of speed, a macro has the advantage.

Q. Explain the common programming errors.

Ans: Common programming errors:
• Missing semicolon: Every C statement must end with a semicolon. A missing semicolon is confusion to the compiler and may result in misleading error messages.
• Missing braces: Very common error as it is common to forget a closing brace. Number of opening braces should match number of closing braces.
• Undeclared variables: C requires declaration of variables before their use.
• Forgetting the precedence of operators: Expression are evaluated according to precedence of operators. It is very common for beginners to forget this.
• Mismatch of parameters in function calls: There may be mismatch in actual and formal parameters in function calls.
• Missing ‘&’ operator in scanf call.
• Crossing the bounds of an array.
• Unending and sometimes wrong loops.
• Using uninitialized pointer that points to garbage.
• Improper comment characters.

Q. When passing parameters to functions, explain the difference between pass-by-value and pass-by-reference.

Ans: The two ways of parameter passing mechanism are:
(i) Pass by value or sending the values of the arguments- The value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. The changes made to the formal arguments have no effect on the values of actual arguments in the calling function. This technique of passing arguments is called pass by value illustrated by the following example.

(ii) Pass by reference or sending the addresses of the arguments- the addresses of actual arguments in the calling function are copied into formal arguments of the called function. Using these addresses we are actually working on actual argument so changes will be reflected in the calling function. This technique of passing arguments is called pass by reference, illustrated by following example.

Q. What is meant by identifiers? How do identifiers differ from keywords?

Ans: Each C word can be classified as either a keyword or an identifier. Identifiers refer to the names of variables, functions and arrays. These are user-defined names and consist of a sequence of letters and digits, with a letter as a first character. Both uppercase and lowercase can be used to form identifiers. Maximum length of an identifier is 8 characters. Some compiler allows length upto 40 characters. Comma and blanks are not allowed. No special symbol except underscore is allowed in identifiers name.
All keywords have fixed meanings and these cannot be changed. Keywords are the basic building blocks for program statement. The keywords also known as reserved words cannot be used as variable names. There are 32 keywords available in C.

Q. What is an array & how is an array variable different from an ordinary variable?

Ans:An array is a collection of data storage locations, each having the same data type and the same name. Each storage location in an array is called an array element. A particular value is indicated by writing a number called index or subscript after array name. For example a[5] stands for 6th element in the array a. The complete set of values is called array while the individual values are called elements. Arrays can be of any variable type.