0% found this document useful (0 votes)
3 views5 pages

Statistical Computing with C Programming

The document provides an overview of statistical computing using C programming, focusing on data types, constants, and their classifications. It details basic data types such as integers, characters, and floating points, as well as derived and enumerated data types. Additionally, it explains different types of constants, including numeric and character constants, along with their rules and examples.

Uploaded by

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

Statistical Computing with C Programming

The document provides an overview of statistical computing using C programming, focusing on data types, constants, and their classifications. It details basic data types such as integers, characters, and floating points, as well as derived and enumerated data types. Additionally, it explains different types of constants, including numeric and character constants, along with their rules and examples.

Uploaded by

Soumabha Bhim
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

0

STATISTICAL COMPUTING
AND NUMERICAL ANALYSIS
USING C PROGRAMMING

DEPARTMENT OF STATISTICS
ASUTOSH COLLEGE
KOLKATA
C Programming asutoshstat@[Link]
1

Statistical Computing using C Programming

Data Types
A data type defines a set of values that a variable can store along with a set of operations that
can be performed on the variable. C supports several different data types of data, each of which
may be represented differently within the computer’s memory. The variety of data types
available allow the programmer to select the type appropriate to the needs of the application.
Data in C/C++ language belongs into one of the following types:

 Basic Data Types


 Derived Data Types
 Enumerated Data Type

Basic Data Types


All C compilers support four basic data types, viz. integer (int), character (char), floating
point, i.e., a number containing a decimal point and/or an exponent (float) and double
precision floating point number, i.e., more significant figures, and an exponent which may be
larger in magnitude (double). The basic data types can be augmented by the use of the data
type qualifiers short, long, signed and unsigned.

 Integer Types: The integer data type consists of a subset of integers. Integer variables
are declared with the keywords int, short, unsigned or long.
 Character Types: A single character can be defined as a character (char) type data.
The qualifier signed or unsigned may be explicitly applied to char.
 Floating Point Types: The real / floating point data type consists of a subset of the
real numbers. A real value is an approximation of the desired real number correct to
certain decimal positions. We can declare floating-point variables using the keywords
float or double. A real value of type float is accurate to six decimal positions, a
real value type double is accurate to twelve decimal positions and a real value type
of long double is even accurate to more than twelve decimal positions.
 The void is also considered as a data type. This is usually used to specify the type of
functions. The type of a function is said to be void when it does not return any value
to the calling function. It can also play the role of a generic type, i.e., it can represent
any of the other standard types.

The following table shows various basic data types and their range.

C Programming asutoshstat@[Link]
2

Declaration Name Type Range


Integer
short int Short Integer -27 to 27-1
Int Integer -215 to 215-1
long int Long Integer -231 to 231-1
Character
char Character -128 to 127
signed char Signed Character -128 to 127
unsigned char Unsigned Character 0 to 255
Floating Point
float Floating Point 3.4 × 10−38 to 3.4 × 1038
double Double Floating Point 1.7 × 10−308 to 1.7 × 10308
long double Long Double Floating Point 3.4 × 10−4932 to 1.1 × 104932

Derived Data Types


The data types which are extracted / derived from basic data types are called derived data types.
These data types can be derived by using the declaration operators or punctuators. For example,
array, function, pointer, class, structure, union, enum, etc.

Enumerated Data Types


In C/C++, we can define our own data type and specify what values a variable of this type can
take. The data type defined this way is known as enumerated (enum) data type. Enumerated
data type helps in enhancing the readability of the code. That is this data type is used to give
name to integer constants. It is declared with keyword enum.

Example: enum color{Red, Yellow, Green, Brown}

The above statement defines four integer constants. Enumerated values by default starts with
0 and incremented by 1. So the above character is as

const int Red = 0

const int Yellow = 1

const int Green = 2

const int Brown = 3

C Programming asutoshstat@[Link]
3

Constants
Constants in C refer to fixed values that do not change during the execution of a program. C
support several types of constants as illustrated below:

Constants

Numeric Constants Character Constants

Integer Real Single String

The following rules apply to all numeric constants:


 Commas and blank spaces cannot be included within the constant.
 The constant can be preceded by a minus sign if desired.
 The value of a constant cannot exceed specified minimum and maximum bounds.
Let us consider each type of constant individually.

Integer Constants
An integer constant is an integer-valued number. Thus it consists of a sequence of digits.
Integer constants can be written in three different number systems: decimal (base 10), octal
(base 8) and hexadecimal (base 16). Beginning programmers, however, rarely use anything
other than decimal integer constants.
A decimal integer constant can consist of any combination of digits from the set 0 through 9.
If the constant contains two or more digits, the first digit must be something other than 0.
Embedded spaces, commas and non-digit characters are not permitted between digits.
Example: Valid example of decimal integer constants are
123 -321 0 654321 +78
The following decimal integer constants are illegal
15 750 20,000 $100

Floating Point Constants


Integer numbers are inadequate to represent quantities that vary continuously, such as
distances, heights, temperatures, prices, and so on. These quantities are represented by numbers
containing fractional parts like 17.548. Such numbers are called real (floating-point) constants.

C Programming asutoshstat@[Link]
4

A floating point constant is a base-10 number that contains either a decimal part or an exponent
or both.
Example: 0.2 827.062 2E-8 1.6667E+8
The interpretation of a floating point constant with an exponent is essentially the same as
scientific notation, except that the base 10 is replaced by the letter E (or e).Thus the number
1.2 × 10−3 would be written as 1.2𝐸 − 3 or 1.2𝑒 − 3.
Note: Floating point constants have a much greater range than integer constants. The value 0.0
is a valid floating point constant.

Single Character Constants


A single character constant (or simply character constant) is a single character enclosed in
single quotation marks.
Example: ‘5’ ‘X’ ‘;’ ‘ ’
Note: Character constant ‘5’ is not same as the number 5. The last constant is a blank space.
Character constants have integer values known as ASCII (American Standard Code for
Information Interchange) values.
Example:
Constant Value
‘5’ 53
‘X’ 88
‘;’ 59
‘ ’ 32

String Constants
A string constant is a sequence of characters enclosed in double quotes. The characters may
be letters, numbers, special characters and blank space.
Example: “Enter” “2020” “X” “Mean Deviation”
Note: A character constant is not equivalent to the single character string constant.
Sometimes certain special characters (e.g., a bank slash or a quotation mark) or certain non-
printing characters (e.g., tab, newline) can be included in a string constant if they are
represented in terms of their corresponding escape sequences.
Example: “\n Enter the value: \n”

C Programming asutoshstat@[Link]

You might also like