You are on page 1of 20

CONSTANT , VARIABLES AND

DATA TYPES
Programming Languages for bioinformatics
BIF507
CHARACTER SET
The words can be used to form words, numbers
and expressions.

Can be grouped into:


Letters
Digits
Special character
White spaces
Types Character Set

Lowercase Letters a-z

Uppercase Letters A to Z

Digits 0-9

Special Characters !@#$%^&*

White Spaces Tab Or New line Or Space

The compiler ignores white spaces unless they are a part of a


string constant.
White spaces can be used to separate words but are prohibited
between the characters of keywords and identifiers
Valid C Characters : Special Characters are listed below
\ Backslash

Symbol Meaning ` Apostrophe


~ Tilde Minus sign

! Exclamation mark = Equal to sign

# Number sign { Left brace

} Right brace
$ Dollar sign
[ Left bracket
% Percent sign
] Right bracket
^ Caret : Colon
Quotation mark
& Ampersand
; Semicolon
* Asterisk
< Opening angle bracket
( Left parenthesis
> Closing angle bracket
) Right parenthesis
? Question mark

_ Underscore
, Comma

+ Plus sign . Period

| Vertical bar / Slash


C TOKENS
Smallest individuals units are called tokens.

C TOKENS

Operators
Keywords
Special Symbols
Identifiers
Constant Strings
KEYWORDS AND IDENTIFIERS
Every C word is classified into either keywords or
identifiers

Keywords have fixed meanings and these meaning


cannot be changed
Keywords serve as basic building blocks for program
statements
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned
Identifiers refers to names of variable, function and
arrays.

Rules for identifiers


1st character must be an alphabet (or underscore)
Must consist of only letters digits or underscore
Only first 31 characters are significant
Must not contain white space.
CONSTANT
Fixed values that do not change during the execution
of a program
Constants

Numeric Constants Character Constants

String
Integer Real Single character Constants
Constants Constants Constants
Integer constant
Can decimal integer or octal integer or hexadecimal
integer
Decimal integer (0-9, preceded by + or - , eg +98 , 653487)
Octal integer (0-7, leading to 0, eg 034, 0456, 0)
Hecadecimal (preceded by 0x/0X, include A-F/a-f, eg. 0x2,
0xF9)

Real constant
Numbers containing fractional parts
Called real or floating points
Can also be represented in exponential notation
215. , .95 , +.6, 0.65e4
Single character constant
Under single qoutes
e.g 5, K, ; ,
Character constant has an integer values (ASCII)

String constant
Under double qoutes
Hello Worlds , 1987

Backlash character constant


Character combination known as escape sequences.
Backslash_character Meaning
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\ Double quote
\ Single quote
\\ Backslash
\v Vertical tab
\a Alert or bell
\? Question mark
\N Octal constant (N is an octal
constant)

\XN Hexadecimal constant (N


hex.dcml cnst)
VARIBALES
Data name used to store a data value.

Case sensitive
DATA TYPES
Three types
Primary
Derived
User Defined
Type Description
char Typically a single octet(one byte). This is
an integer type.
int The most natural size of integer for the
machine.
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255

unsigned char 1 byte 0 to 255


signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648
to 2,147,483,647

unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295

short 2 bytes -32,768 to 32,767

unsigned short 2 bytes 0 to 65,535


long 4 bytes -2,147,483,648 to 2,147,483,647

unsigned long 4 bytes 0 to 4,294,967,295


Integer type
short int
int
long int
Floating point types
float
double
long double
Void type
No value
To specify function
Character type
signed
unsigned
DECLARATION OF VARIABLES
Variable name
Type of varibae
eg data-type v1,v2;

User defined declaration

typedef type identifier


Eg typedef int units;
typedef float marks;

units batch1, batch2;


marks name1, name3;
ASSIGNING VALUES TO VARIBLES
Variable_name = constant;

Known as assignment statement

Data_type Variable_name = constant;


READING FROM KEYBOARD

Scanf (control string, &variable1, & variable2);

& ampersand(directs to variable)

Control string
%d, %f, %c, %s
END

You might also like