Consider line number of the following C-program.
int main() { /*Line 1 */
int I, N; /*Line 2 */
fro (I=0, I<N, I++); /*Line 3 */
}
Identify the compiler’s response about this line while creating the object-module:
View worked solution
Answer: A
To determine the compiler's response to Line 3, let us analyze it phase-by-phase during compilation:
fro (I=0, I<N, I++);
- Lexical Analysis:
- The lexer groups characters into tokens.
frois not a keyword, but it is a perfectly valid sequence of characters representing an identifier (like a variable or function name).- Therefore, there is no lexical error.
- Syntax Analysis (Parsing):
- Since
frois treated as an identifier, the parser interprets the statement as:identifier ( expression , expression , expression ) ; - This matches the syntax of a function call to a function named
frowith three arguments separated by the comma operator. - Therefore, there is no syntax error.
- Since
- Compilation to Object Module:
- In C (specifically C89/C90, which was the standard at the time of this question), calling an undeclared function is permitted under the implicit function declaration rule (the compiler assumes the function returns an
int). - This might trigger a compiler warning, but it does not prevent the successful compilation and creation of the object module.
- The actual error (undefined reference to
fro) will only be raised by the linker, not during the compilation phase.
- In C (specifically C89/C90, which was the standard at the time of this question), calling an undeclared function is permitted under the implicit function declaration rule (the compiler assumes the function returns an
Thus, there is no compilation error while creating the object module.
Free practice · Your answers on this page are not saved.
