Sunday, 16 October 2011

Chapter 1: [B] Point out the errors, if any, in the following C statements:

(a)  int = 314.562 * 150 ;

C keyword is used as variable name. 



(b)  name = ‘Ajay’ ;

Char can only store 1 character.Also only single sided single quotes are used to enclose char.



(c)  varchar = ‘3’ ;

only single sided single quotes are used to enclose char.

varchar = '3' ; is correct



(d)  3.14 * r * r * h = vol_of_cyl ;

One and only one variable can be at the left side of an expression.



(e)  k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;

It is assumed that arithmetic operators (*) are already present. When they are not



(f)  m_inst = rate of interest * amount in rs ;

No spaces are allowed in c variable names.



(g)  si = principal * rateofinterest * numberofyears / 100 ;

No error



(h)  area = 3.14 * r ** 2 ;

(*) is repeated        

area = 3.14 * r * 2 ;is corect



(i)  volume = 3.14 * r ^ 2 * h ;

There is no exponential operator in C.



(j)  k = ( (a * b ) + c ) ( 2.5 * a + b ) ;

(*) is missing

k = ( (a * b ) + c ) *( 2.5 * a + b ) ; is correct.


(k)  a = b = 3 = 4 ;

A single variable can not store more than one values.



(l)  count = count + 1 ;

No error



(m)  date = '2 Mar 04' ;

Char can only hold a single character.

13 comments:

  1. good explain sir thankuuu soo much

    ReplyDelete
  2. Very informative, thank you.

    ReplyDelete
  3. its very helpful for our study, thank you sir for this informations and answers.i hope more these type blogs from you.

    ReplyDelete
  4. Very informative, its very helpful for our study,thank you.

    ReplyDelete
  5. Plz tell me what is the error in the following c statement:- USA$=A

    ReplyDelete
    Replies
    1. No special symbol other than underscore can be used to construct variable name . Here $ is makes it invalid.

      Delete
  6. Plz tell me what is the error in following c statement:- for(i>1;i=10;i++)

    ReplyDelete