Chapter 1
Getting started
[A] Which of the following are invalid variable names and why?
BASICSALARY
● It is a valid variable
_basic
● It is a valid variable
Basic-hra
● Hyphen is not valid between 2 words
#MEAN
● # is not valid in the name of a variable
group.
● Full stop is not valid in the name of a variable
422
● Variable has combination of letters and [Link] only digits
population in 2006
● There shouldn't be any gap between words
over time
● There shouldn't be any gap between words
Mindovermatter
● It is a valid variable
FLOAT
● It is a valid variable
hELLO
● It is a valid variable
queue.
● Full stop is not valid in the name of a variable
team’svictory
● ‘ is not valid in the name of a variable
Plot # 3
● There shouldn't be any gap between words
2015_DDay
● Variable starts with digits making it invalid
[B] Point out the errors, if any, in the following C statements:
(a) int = 314.562 * 150 ;
Int is the variable name for integer but the value assigned is a float
(b) name = ‘Ajay’ ;
There should only be one letter and inverted commas are wrong
(c) varchar = ‘3’ ;
inverted commas are wrong
(d) 3.14 * r * r * h = vol_of_cyl ;
Variable must be on the left side
(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
* missing between brackets
(f) m_inst = rate of interest * amount in rs ;
Gap between words
(g) si = principal * rateofinterest * numberofyears / 100 ;
It should be written as (principal * rateofinterest * numberofyears) / 100
(h) area = 3.14 * r ** 2 ;
There is no r ** 2 function in C
(i) volume = 3.14 * r ^ 2 * h ;
There is no r ^ 2 function in C
(j) k = ( (a * b ) + c ) ( 2.5 * a + b ) ;
It should be written as (a * b ) + c )*( 2.5 * a + b )
(k) a = b = 3 = 4 ;
A and b should be assigned values separately
(l) count = count + 1 ;
It is valid
(m) date = '2 Mar 04' ;
There is space and multiple letters in character
[F] What would be the output of the following programs:
(a) main( )
{
int i = 2, j = 3, k, l ;
float a, b ;
k=i/j*j;
l=j/i*i;
a=i/j*j;
b=j/i*i;
printf( "%d %d %f %f", k, l, a, b ) ;
}
Output: 0 2 0.00 2.00
(b) main( )
{
int a, b ;
a = -3 - - 3 ;
b = -3 - - ( - 3 ) ;
printf ( "a = %d b = %d", a, b ) ;
}
Output: Error
(c) main( )
{
float a = 5, b = 2 ;
int c ;
c=a%b;
printf ( "%d", c ) ;
}
Output: 1
(d) main( )
{
printf ( "nn \n\n nn\n" ) ;
printf ( "nn /n/n nn/n" ) ;
}
Output: nn
nn
nn /n/n nn/n
(e) main( )
{
int a, b ;
printf ( "Enter values of a and b" ) ;
scanf ( " %d %d ", &a, &b ) ;
printf ( "a = %d b = %d", a, b ) ;
}
Output: Enter values of a and b 1 2
a=1b=2
(f) main( )
{
int p, q ;
printf ( "Enter values of p and q" ) ;
scanf ( " %d %d ", p, q ) ;
printf ( "p = %d q =%d", p, q ) ;
}
Output: Error