0% found this document useful (0 votes)
5 views3 pages

Chapter 1 Getting started

The document discusses valid and invalid variable names in programming, highlighting specific examples and the reasons for their validity. It also points out errors in C statements, explaining the mistakes and providing corrections. Additionally, it presents outputs for various C programs, indicating expected results and errors.

Uploaded by

azankhan4744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Chapter 1 Getting started

The document discusses valid and invalid variable names in programming, highlighting specific examples and the reasons for their validity. It also points out errors in C statements, explaining the mistakes and providing corrections. Additionally, it presents outputs for various C programs, indicating expected results and errors.

Uploaded by

azankhan4744
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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 digits.not 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

You might also like