Академический Документы
Профессиональный Документы
Культура Документы
Constants:
The quantity whose value cannot change during the execution of the program
is called constant. It may be a numeric or a non numeric quantity.
Variables
A quantity whose value may change during execution of the program is called
variable. It may be a numeric or a non-numeric quantity. It is represented by a symbol
called variable name. The variable name consists of alphabets and digits.
A variable represents a storage or memory location in the computer memory.
Data is stored into the memory location. The name of the memory location, i.e. the
variable name, remains fixed during execution of the program but the data stored in
that location may change from time to time.
Data Types in C:
The actual values used in a program are called data. There are four basic types of data
in C. these are:
int Integer
float Real Values
double Large real values
char Characters
Data Types
Type Size in Bytes Data storage Range
int 16 bits (2 bytes) -32768 to 32767
short int 16 bits (2 bytes) -32768 to 32767
long int 32 bits (4 bytes) -2147483648 to
2147483647
unsigned int 16 bits (2 bytes) 0 to 65635
unsigned long int 32 bits (4 bytes) 0 to 4294967295
float 32 bits (4 bytes) 1.1x10-38 to 3.4x10+38
long float 64 bits (8 bytes) 2.2x10-308 to 1.7x10+308
double 64 bits (8 bytes) 2.2x10-308 to 1.7x10+308
long double 80 bits (10 bytes) 3.4x10-4932 to 1.1x10-4932
char 8 bits (1 bytes) In case of strings, storage
capacity is from 1 byte to
65535 bytes.
1. int
2. short int
3. long int
4. unsigned int
The int:
The range of values of int data type depends upon the computer system being
used and it takes two to four bytes. In MS DOS, an integer type variable takes two
bytes in the memory and the range of values stored is from -32768 to 32767.
The maximum and minimum values for integer data types are specified in
integer.h header file. The minimum integer value is defined by INT_MIN and
maximum integer value is defined by INT_MAX.
1. float
2. double
Q6: Explain how real numbers are expressed in scientific or exponential notation?
A real type data can also be represented in exponential form. In this form, a real
number is divided into two parts i.e. a mantissa and an exponent. The general form of
a real number in exponential form is:
±mE ±n or ±me ±n
where
m represent the mantissa. It has an absolute value greater than or equal to
1.0 and less than 10.0
n represents the value of exponent. It is a real number.
For example, the real number 15000000.0 can be written in scientific form as: 1.5 x
106. In exponential form it can be written as +1.5e+6 or 1.5e6
Where 1.5 represents mantissa (m) and 6 shows the value of exponent (n).
The following table gives a real number and its equivalent scientific and exponential
forms.
Integer Constants
A numerical value without a decimal is called integer constant. The minus (-)
sign is used to indicate a negative integer constant. The use of (+) sign with a positive
integer constant is optional.
Integer constants are used in expressions for calculations. The Integer
constants are written without ".", "e", or "f". For example:
1000 -87
The long integer constants are written with L appended. For example:
8000000L -86316L
Character Constants
A single character enclosed in single quotation marks is called character
constant. For example 'a', '/', and '+' represent character constants.
String Constants
A sequence of characters consisting of alphabets, digits and/or special
characters enclosed in double quotation marks is called string constants. For example,
"Pakistan" and "Lahore" are examples of string constants.
The long integer type variables are declared using the long int keyword. For example,
to declare a variable "length" of long integer type, the statement is written as:
long int length;
The float type variables are declared using the float keyword. For example, to declare
a variable "length" of float type, the statement is written as:
float height;
The double type variables are declared using the double keyword. For example, to
declare a variable "distance" of double type, the statement is written as:
double distance;
The long double type variables are declared using the long double keyword. For
example, to declare a variable "huge" of long double type, the statement is written as:
long double huge;
The character type variables are declared using the char keyword. For example, to
declare a variable "nm" of char type, the statement is written as:
Char nm;
More than one variable of the same data type can also be declared in one statement. In
this case, the names of the variables are written after the keyword separated by
commas. For example, to declare three variables "xyz", "d" and "s" of integer type,
the statement is written as:
Int xyz, d, s;
To declare different types of variables, different statements are used. For example, to
declare variables a and xy as int types, b as float type, nm as character type and sum
as double type, the statement are written as:
int a, xy;
float b;
char nm;
double sum;