Chapter
No-02(Constants, Variables and Data Types)
===================================================================================
** State whether the following statements
are true or false:
(a)
Any valid printable ANSII character
can be used in an identifier.(False)
(b)
All variables must be given a type
when they are declared. ( True )
(c)
Declarations can appear anywhere in
a program. ( False )
(d)
ANSI C treats the variable name and
Name to be same. ( False )
(e)
The underscore can be used anywhere
in an identifier. ( True )
(f)
The keyword void is a data type in
C. ( True )
(g) Floating point data constants, by
default, denote float type values.(False )
(h)
Like variables, constants have a
type. ( True )
(i)
Character constants are coded using
double quotes. (False )
(j) Initialization is the process of
assigning a value to a variable at the time of declaration. ( true )
(k)
All static variables are
automatically initialized to zero. ( True )
(l)
The scanf function can be used to
read only one value at a time.(False)
**Fill in the blanks with appropriate words:
(a)The keyword int can be used to create a data
type identifier.
(b) 255 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 qualifier constant At the time of initialization.
** What are tri-graph characters? How are they useful?
Answer: Trigraph characters is one
kinds of character which consists of three characters ( Two question marks and
followed by another ).
Some
keyboard does not support some characters. But we can use them by trigraph
characters. If a keyboard does not support square brackets, we can still use
them in a program using the trigraph ??( and ??) .
**Describe the four basic data types. How could we extend the range of
values they represent?
Answer: The basic four data types are:
(1)
char
(2)
int
(3)
float
(4)
double
We cannot extend the range of character. We could extend
the
range of integer by using long
before integer. We can extend the range of float by using double. To extend the
precision further we may use long double.
** What is an unsigned integer constant? What is the significant of
declaring a constant unsigned?
Answer: The integer constant which
does not take any + or – sign before it is called an unsigned integer constant.
We can take the value double using
an unsigned integer constant. For example, a signed integer constant have a
value between -32768 to +32767, but an unsigned integer constant takes the
value between 0 to 65535.
** Describe the characteristics and purpose of escape sequence characters.
Answer: C supports some special
back slash character constants, that are used in output function. This
characters are known as escape sequence characters. For example, the symbol
“\n” stands for new line character.
Characteristics :
(1)
They acts as a single character.
(2)
Each escape sequence character
consists of two characters.
(3)
The first character must be a back
slash .
(1) In a program we used it for new
line. (2)In a program we used it for horizontal tab.
** What is a
variable and what is meant by “value” of a variable?
Answer: A variable is a data name
that may used to store a data value. Like constants that remains unchanged
during the execution a program.
The meant of value it is a variable
name and it can take any value like character, int, float and double.
** How do
variables and symbolic names differ?
Answer: A variable may be used to
store data value. A variable may take different values at different times
during execution of a program. Variables has need to declare at the beginning
of the body but after
the main.
Symbolic
names is a unique constants. This constants may appear in a number of place in
the program. Symbolic names has need to define at the beginning of a program.
** State the difference between the declaration of a variable and the
definition of a symbolic name?
Answer: Variables has need to
declare at the beginning of the body but after the main. The syntax for
declaring a variable is as follow:
Data-type v1,v2,……..vn;
v1, v2,……..vn
are the names of variables. For example, valid declarations are
int count;
int number,
total; float ratio;
Symbolic names has need to define
at the beginning of a program. A symbolic name constants is defined as follows:
#define symbolic-name value of constant
Valid example
of constant definations are: #define STRENGTH 100 #define PASS MARK 5
** What is
initialization? Why it is important?
Answer: The process of giving
initial values to variables is called initialization. Some examples are
int final_value =100; char yes
=’x’; double balance =75.84;
C permits the initialization of
more then one variable using multiple assignment operators. For example the
statements
p=q=s=0;
x=y=z=MAX;
are valid.
**What are the
qualifiers that an int can have at a time?
Answer: A signed int can take a
value between -32768 to 32767 and an unsigned int can take a value 0 to 65535.
** Describe the
purpose of the qualifiers constant and volatile.
Answer: We may like the value of
certain variables to remain constant during the execution of a program. We can
achieve this by declaring the variable with the qualifier constant at the time
of initialization. Example:
const int class_size=40;
ANSI standard
defines another qualifier volatile that could be used to tell explicitly the
complier that a variables value may be changed at any time by some external
sources (from outside the program).
For example:
|
volatile int date;
|
|
|
|
|
|
|||
** When dealing with very small or very large numbers, what steps would
you like you take to improve the accuracy of the calculation?
Answer:
When we are dealing with a very short number we can improve the accuracy of
calculation by using a keyword short before the keyword. Example short int.
When we are dealing with a very
large number we can improve the accuracy of calculation by using a keyword long
before the keyword. Example long int.
** Which of the
following are invalid constants and why?
|
Expression
|
|
|
Validity
|
|
|
Reasons
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
0.0001
|
|
|
(valid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5x1.5
|
|
Invalid
|
|
Exponent must be an integer
|
|
||||
|
|
|
|
|
|
|
|
||
|
99999
|
|
|
Valid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+100
|
|
|
valid
|
|
|
|
|
||
|
|
|
|
|
|
|
|||
|
75.45E-2
|
|
|
Valid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-45.6
|
|
|
Valid
|
|
|
|
|
||
|
|
|
|
|
|
||||
|
“15.75”
|
|
|
Invalid
|
|
|
“” sign is not permitted
|
|
|
|
|
|
|
|
|
|
|
|
|
-1.79e+4
|
|
valid
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
||
|
0.00001234
|
|
|
Valid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Which of the
following are invalid variable and why?
|
Expression
|
|
|
Validity
|
|
|
Reasons
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
Minimum
|
|
|
valid
|
|
|
|
|
|
|
First.name
|
|
Invalid
|
(.)Sign is not permitted
|
|
|
|
||||
|
N1+n2
|
|
|
Invalid
|
|
+ sign is not permitted
|
|
|
|
|
&name
|
|
Invalid
|
& is not permitted
|
|
|
|
||||
|
|
|
|
|
||||||
|
Doubles
|
|
|
Valid
|
|
because Keyword may be a part of variable
|
|
|||
|
|
|
|
|
|
name
|
|
|
|
|
3rd_row
|
|
Invalid
|
First character must be a letter or underscore
|
|
||||||
|
n$
|
|
|
Invalid
|
|
Dollar sign is not permitted
|
|
|
|
|
Row1
|
|
Valid
|
|
|
|
|
|
|||
|
Float
|
|
|
Invalid
|
|
float is a keyword
|
|
|
|
|
Sum Total
|
|
Invalid
|
White space is not permitted
|
|
|
|
||||
|
Row Total
|
|
|
Invalid
|
|
White space is not permitted
|
|
|
|
|
Column total
|
|
Invalid
|
White space is not permitted
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
- You can download this file as pdf by clicking below download icon-
- Download
Go ahead by honesty--->Rm
No comments:
Post a Comment