Let us C book Chapter 1 Exercise Solutions

 [A] Which of the following are invalid C constants and why?

‘3.15’ : Valid C Constant falls into Real Constant category

35,550 : Invalid C Constant because comma is not allowed 

3.25e2 : Valid Exponential format of Real Constant 

2e-3 : Valid Exponential form of Real Constant 

‘eLearning’ : Invalid C Constant Because Only ONe character should be there and single quote present 

“Show” : Valid C Constant 

‘Quest’ : Invalid C Constant because single quote present instead of double 

2^3 : Invalid C Constant 

4 6 5 2 : Invalid C Constant because spaces not allowed 


[B] Which of the following are invalid variable names and why?

B’day : Invalid Variable Name because single quote present 

Int : Invalid Variable name because it is a reserved Keyword 

$hello : Invalid C Variable Name 

#Hash : Invalid because only alphabets, digits and underscores allowed in naming variable 

Dot.  : Invalid 

Number : Valid 

totalArea : Valid 

_main() : Invalid, variable name cannot have () 

Temp_in_deg : Valid 

total% : Invalid 

1st : Valid 

Stack-queue : Invalid 

Variable name : Invalid you cannot have space 

%name% : INvalid because you cant have %

Salary : Valid 


True or False 

(a) C language has been developed by Dennis Ritchie. : TRue

(b) Operating systems like Windows, UNIX, Linux and Android are

written in C.

True 

(c) C language programs can easily interact with hardware of a PC /

Laptop

True 

(d) A real constant in C can be expressed in both Fractional and

Exponential forms

True 

(e) A character variable can at a time store only one character. : True

(f)

The maximum value that an integer constant can have varies from

one compiler to another.

True

(g) Usually all C statements are written in small case letters.

True 

(h) Spaces may be inserted between two words in a C statement. True 

Spaces cannot be present within a variable name. True 

C programs are converted into machine language with the help of a

program called Editor.

 False its compiler 

(k) Most development environments provide an Editor to type a  

program and a Compiler to convert it into machine language.

True 

(l)

int, char, float, real, integer, character, char, main, printf and scanf

all are keywords.

False because integer, character , main , printf, scanf are not keywords 


MAtch the following 

A \n : Escape Sequence 

B 3.1345 -> Real Constant 

C -65313 -> Integer Constant 

D ‘D’ -> Character COnstant 

E 4.25e-3 -> Exponential form 

F main() -> function 

G %f, %d, %c -> Format Specifier 

H ; -> Statement Terminator 

I Constant -> Literal 

J Variable -> Identifiers 

K & -> Address of operator 

L printf() -> Output Function 

M scanf() -> Input Function 



[E] Point out the errors, if any, in the following programs:

(a) int main( )

{

int a, float b, int c ;

a = 25 ; b = 3.24 ; c = a + b * b – 35 ;

}


Int a, float b, int c -> Wrong writing

Correct syntax -> int a,c; float b;

c = a + b * b – 35 ; -> - absent


(b) /* Calculation of average

/* Author: Sanjay */

/* Place – Whispering Bytes */

*/

#include <stdio.h>

int main( )

{

int a = 35 ; float b = 3.24 ;

printf ( "%d %f %d", a, b + 1.5, 235 ) ;

}


Comments are incorrectly used 

/* /* */  -> Right use /*  */


(c) #include <stdio.h>

int main( )

{

int a, b, c ;

scanf ( "%d %d %d", a, b, c ) ;

}

Perfect 


(d) #include <stdio.h>

int main( )

{

int m1, m2, m3

printf ( "Enter values of marks in 3 subjects" )

scanf ( "%d %d %d", &m1, &m2, &m3 )

printf ( "You entered %d %d %d", m1, m2, m3 ) ;

}

Semicolon not used 


Comments

Popular posts from this blog

Use your old android phone as a Wifi router/Access point for your home network to extend Wi-fi Signal

Data Structures book chapter 3 exercise solutions