Let Us C
by YASHAVANT P. KANETKARChapter 1: Getting Started (PAGE:39)
Exercise
[A] Which of the following are invalid variable names and why?
BASICSALARY
1)_basic
OK
2)basic-hra
WRONG
No special symbol
other than undersccore can be used in a variable name.
3)#MEAN
WRONG
No special symbol
other than undersccore can be used in a variable name.
4)group.
WRONG
No special symbol
other than undersccore can be used in a variable name.
5)422
WRONG
The first character in
the variable name must be an alphabet or imderscore(_)
6)population in 2006
WRONG
No commas or blanks
are allowed within a variable name.
7)over time
WRONG
No commas or blanks
are allowed within a variable name.
8)mindovermatter
Correct
9)FLOAT
WRONG
Keywords can not be
used as variable names if we do so, we are trying to assign a new meaning to
rhe keywoed which is not allowed by the computer.
10)hELLO
OK
11)queue.
WRONG
No special symbol
other than undersccore can be used in a variable name.
12)team'svictory
WRONG
No special symbol
other than undersccore can be used in a variable name.
13)Plot # 3
WRONG
No special symbol
other than undersccore can be used in a variable name.
14)2015_DDay
WRONG
The first character in
the variable name must be an alphabet or imderscore(_)
[B] Point out the
errors, if any in the following C statements:
(a) int =
314.562 * 150
Correction = float = 314.562*150
(b) name = 'ajay';
OK
(c) varchar = '3';
OK
(d) 3.14*r*h = vol_of_cyl;
Correction = vol_of_cyl = 3.14*r*h;
(e) k = (a*b)(c+(2.5a+b)(d+e)
(f)m_inst = rate of interest*amount in rs;
Correction = m_inst = rate_of_interest*amount_in_rs;
(g) si = principal*rateofinterest*numberofyears/100;
OK
(h)area = 3.14*r**2;
Correction => area
= 3.14*r*r;
(i) volume =>
3.147*r*r*h;
(j) k = ((a*b)+c)(2.5*a+b)
Correction => k = ((a*b)+c)*(2.5a+b)
(k) a = b = 3 = 4
Correction => a = b = 3
(l) count = count +1;
OK
m) date = '2Mar 03;
OK
Exercise
[A] Which of the following are invalid variable names and why?
1)_basic
OK
5)422
6)population in 2006
WRONG
Correction = float = 314.562*150
(b) name = 'ajay';
(c) varchar = '3';
OK
(d) 3.14*r*h = vol_of_cyl;
Correction = vol_of_cyl = 3.14*r*h;
(e) k = (a*b)(c+(2.5a+b)(d+e)
(f)m_inst = rate of interest*amount in rs;
Correction = m_inst = rate_of_interest*amount_in_rs;
(g) si = principal*rateofinterest*numberofyears/100;
OK
(h)area = 3.14*r**2;
(j) k = ((a*b)+c)(2.5*a+b)
Correction => k = ((a*b)+c)*(2.5a+b)
(k) a = b = 3 = 4
Correction => a = b = 3
(l) count = count +1;
m) date = '2Mar 03;