in Compiler Design retagged by
2,909 views
14 votes
14 votes

Consider the following programming errors:

  1. Type mismatch in an expression.
  2. Array index out of bounds.
  3. Use of an uninitialized variable in an expression.

Which of these errors will typically be caught at compile-time by a modern compiler.

  1. I, II and III
  2. I and II
  3. I and III
  4. None of them
in Compiler Design retagged by
2.9k views

1 comment

2 Answers

12 votes
12 votes
Best answer

Type mismatch gives compile time error for statically typed languages (type of variables are determined at compile time) like C. 

Use of uninitialized variable can be detected by compiler? Not always- but possible in most cases. There can be cases where there are two branches and a variable is initialized in one but not in other. But, at compile time we can assume that we are only interested in those variables which are uninitialized in all the branches,

Array index out of bounds- can be detected by compiler in some cases. Consider 

int a[100];
a[200] = 4;

A decent C compiler should catch this. But if the index is a variable it becomes more difficult to catch at compile time. 

So, answer should be C

edited by
by

4 Comments

SEMANTIC ANALYZER.

source- ULMAN
0
0

Sir @Arjun what about the SEGEMENTATION FAULT  that we encounter

.

0
0

@sayan chowdhury It is a runtime error and the question is about compile time error.

1
1
–2 votes
–2 votes

Ans D)None of them
 

  • Array index out of bound will not caught in compile time
  • use of uninitialized variable could find in runtime , which could give unexpected result
edited by

3 Comments

even Use of an uninitialized variable in an expression.will not give compile time  error.

Type mismatch in an expression may not give compile time  error not sure.
0
0
Type mismatch could give compile or runtime error both rt?
0
0

this is the correct answer . only 1 will be detected by a compiler.

in case of extern variable .

0
0

Related questions