Assignment- 2
Q1.
state whether the following statement are true or false.
(a)Any valid printable ASCII character can be used in an
identifier.
Ans. False
(b)All variables must be given a type when they are declared.
Ans. True
(c)Declarations can appear anywhere in a program.
Ans. True
(d)ANSI C treats the variable name and NAME to be same.
Ans. False
(e)The underscore can be used anywhere in an identifier.
Ans. False
(f)The keyword void is a data type in C.
Ans. False
(g)Floating point constants, by default, denote float type
values.
Ans. True
(h)Like variables, constants have a type.
Ans. True
(i)Character constants are coded using double quotes.
Ans. True
(j)Initialization is the process of assigning a value to a
variable at the time of declaration.
Ans. True
(k)All static variables are automatically initialized to
zero.
Ans. True
(l)The scanf function can be used to read only one value at a
time.
Ans. True
Q2.
Fill in the blanks with appropriate words.
(a)The keyword Int and double can be used to create a
data type identifier.
(b)65535 is the largest value that an unsigned short
int type variable can store.
(c)A global variable is also known as external
variable.
(d)A variable can be made constant by declaring it with the default
at the time of initialization.
Q3.What
are trigraph character? How are they useful?
Ans. Many non-english keywords do not support all the
charactoris. ANSI-C introduces the concept of ‘trigraph’ sequence to provide a
way to enter certain characters that are not available on some keywords.
-Each trigraph sequence consists of the true characters.
-For EX:- If a keyboard does not support square brackets, we
can still use them in a program using trigraphs.
Q6.Describe
the characteristics and purpose of escape sequence characters.
Ans. Some special bake slash character constant that are used
in output functions.
-A list of such backslash character constants each one their
represents one characters.
-Although they consist of two characters.
-The combination of these characters are known as escape
sequences.
- sequence:-
‘\n’ - New
line
‘\t’ -
Horizontal tab
Q13.What
are enumeration variable? How are they declared? What is the advantages of
using them in a program?
Ans.Enumerated data type provided by ANSI stander. It is
defined as follows:
Enum identifier
{value1, value2,……, value};
-The identifier is a user defined enumerated data type which
can be have one of the values enclosed within the braces (known as enumeration
constants). After this definition, we can declared variables to of this ‘new’
type as below:
Enum identifier
v1, v2….vn;
-The enumerated variables v1, v2….vn can only have one of the
value1, value2,…..,value.
-The assignments of the following types are valid.
V1= value3;
V5=
value1;
An example:-
Enum day
{Monday, Tuesday,….., Sunday}
Enum day
week_st, week_end;
Week_st =
Monday;
Week end =
Friday;
If (week_st ==
Tuesday)
Week_end= Saturday;
-The compiler automatically assigns integer digits beginning
with 0 to all the enumeration constants. That is enumeration constant value 1
is assigned 0, value2 is assigned 1 and so on. However the automatic
assignments can be over bidden by assigning values explicitly to the enumeration
constants.
Q14 . Describe the purpose of the qualifiers const and volatile.
Ans. Const:-
Const int
class size=40;
-const is a new data type qualifier define by ANSI standard.
This tells the compiler that the value of the int variable class –size must not
be modified by the program however, it can be used on the right hand side of an
assignment statements like any other variable.
-volatile:-
ANSI standard
defines another qualifier volatile that could be used to tell explicitly the
compiler that a variables value may be changed at any time by some external
sources (from outside the program).
-example:-
Volatile
int date;
Q16.Which
of the following are invalid constants and why?
Ans.<1>0.0001 – valid
<2>+ 100
– valid
<3>-45.6
– valid
<4>5x1.5
– invalid
-No ’x’ special
character is allowed.
<5>75.45E-2 – valid
<6>-1.79e+4 – valid
<7>99999
– valid
<8>”15.75” – invalid
-Quationts are
not allowed.
<9>0.0001234 – valid
Q17.Which
of the following are invalid variable names and why?
Ans. (1) doubles – it is a keyword
(2) float – it
is a keyword
(3) sum total
– it consist of a blank space.
(4) & Name
– it must start with letter.
Q18.
Find errors if any in the following declaration statements.
Ans. Error
-Declaration
terminated incorrectly.
-Undefined symbol
‘exponent’.
-Statement missing.
-Undefined symbol
‘m’.
-Undefined symbol
‘n’.
-Undefined symbol ‘z’
-Statement missing
declaration for ‘m’.
-Multiple declaration
for ‘m’.
-Undefined symbol
‘court’.
=> Int x;
Float letter,
Digit
Double, f, g,
exponent, alpha, beta, m, n, z, o
Integer
Short char c;
Long int count;
Long float temp;
Q19.
What would be the value of x after execution of the following statement.
Ans. Int x, y = 10;
Char z = ‘97’;
X = y + z
X = 10 + 97
X = 107.
Q20.
Identify syntax errors in the following program. After corrections, what output
would you expect when you execute it?
Ans.
#define PI
3.14159
Main()
{
Int R, C;
Float
perimeter;
Float area;
C = PI;
Parameter = 7.0*c*R
Area = C*R*R
Printf (“%f, %f, %d” & parameters, & area)
-
Here
in this line comment is must complete
/*
R. Radios of circle*/
-
The
line should be completed with semicolon C=PI;
-
The
printf function is among.
Printf (“%f”, parameter, area);
#define PI 3.14159
Main()
{
Int R, C /*R. Radios at circle*/
Float parameter /*Circumstance of
circle*/
Float area /*area of circle*/
C=PI;
R=S;
Perimeter = 20*C*R;
Area = C*R*R;
Printf (“%f %f “, perimeter, areas”);
}
-
Error
(1)
Statement
missing.
(2)
Undefined
symbol ‘parameter’.
(3)
Undefined
symbol ‘area’.
(4)
Undefined
symbol ‘parameter’.
(5)
Statement
missing.
No comments:
Post a Comment