Chapter - 2: C Instructions

Point out the errors, if any, in the following C statments:


A
Sections
1
Exercises

(a) x = (y + 3);

Valid.

 

(b) cir = 2*3.141593*r;

Valid.

 

(c) char = '3';

Error: char is a reserved keyword and cannot be used as a variable. We cannot assign anything to a keyword.

 

(d) 4/3*3.14*r*r*r = vol_of_sphere

Error: lvalue required. We cannot take any expression on the left of the assignment operator.

 

(e) volume = a3;

Error: a3 do not specify any operation.

 

(f) area = 1/2*base*height;

Valid.

 

(g) si = p*r*n/100;

Valid.

 

(h) area of circle = 3.14*r*r;

Error: space is not allowed in variable names.

 

(i) per_of_tri = a + b + c;

Valid.

 

(j) slope = (y2 - y1)÷(x2 - x1);

Error: This '÷' is not a valid operator.

 

(k) 3 = b = 4 = a;

Error: lvalue required. Left side should not have any constant value or any expression.

 

(l) count = count + 1;

Valid.

 

(m) char ch = '25 Apr 12';

Error: character length must be of one.


© 2021 Garbage Valuegarbage value logo