985 views
0 votes
0 votes

int main(){

int a = 10;

fun(a);

}

void fun(int a){

printf(“%d”,a);

}

Which phase of the compiler will raise an error?

  1. Lexical 
  2. syntax
  3. semantics
  4. none of the above

3 Answers

1 votes
1 votes

This would be detected during syntax analysis only, this is because the production would expect an ampersand before "a" in the line: printf(“%d”,a); 

But there won't be any such productions. 

0 votes
0 votes
It will generate syntax error because , in the main() function when we call fun(a) , it doesn't recognize what it is because our program is read from top to bottom. It will generate definition missing error because it doesn't know about fun(a).
To avoid this we can put the definition of the function before main() as
void fun(int a); .

Related questions

1 votes
1 votes
1 answer
1
rahul sharma 5 asked Apr 28, 2018
1,442 views
int a = b+*/c;Which phase will give the error?Lexical or syntax?
1 votes
1 votes
0 answers
2
Rahul_Rathod_ asked Jan 3, 2019
411 views
is given solution correct?
0 votes
0 votes
2 answers
4
snakeeye asked Jun 19, 2016
3,644 views
Analysis which determines the meaning of a statement once its grammatical structure becomes known is termed as (A) Semantic analysis (B) Syntax a...