retagged by
2,871 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
retagged by

2 Answers

Best answer
12 votes
12 votes

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
–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

Related questions

8 votes
8 votes
5 answers
3
go_editor asked May 22, 2016
1,935 views
A man has three cats. At least one is male. What is the probability that all three are male?$\frac{1}{2}$$\frac{1}{7}$$\frac{1}{8}$$\frac{3}{8}$
7 votes
7 votes
2 answers
4