FPL 1
FPL 1
1 0 1 1 0 0 1 0
■ Representation of 1
0 0 0 0 0 0 0 1
■ Representation of 9
0 0 0 0 1 0 0 1
Letters: Alphabets
uppercase A….Z and
lowercase a….z
Legal characters i.e.
characters that are allowed
in C
Digits:
0,1,2,3,4,5,6,7,8,9
Types of
tokens:
Special
Keywords Identifiers Constants Strings Symbols Operators
Keywords:
Identifiers:
Variables
■ Variable comes in different types based on the value it has been assigned:
– int roll_num = 4; //This is variable is integer type variable since it has been
declared as “int”
– float percent = 76.46; //Since we are assigning fractional to the variable, we need
to use ”float” as variable indentifier
– char alpha = ‘a’; //To represent character values, char identifier has been used.
– ‘int’ to represent integer values, float to represent floating point/fractional values
or ‘char’ to represent character type values of variables are called to data types.
– According to Wikipedia data types “constitute the semantics and characteristics of
storage of data elements”
Primitive data types
■ We must assign a data type to
all the variables that are
present in the C language.
These define the type of data
that we can store in any
variable. If we do not provide
the variable with a data type,
the C compiler will ultimately
generate a syntax error or a
compile -time error.
■ The variables can be of the
basic types, based on the
name and the type of the
variable.
■ There are three Data Types
used in C:
– Primitive
– Derived types
– User defined
Integer data type
■ Used to represent floating points. Its size is 4 byte long. Range is -2,147,483,648 to
2,147,483,647. It has precision of 7 digits
– float pi = 3.141592;
■ In case higher precision needed to represent floating values, ‘double’ keyword is
used. The size of double is 8 byte long. It has precision of 15 digits.
– double pi = 3.14159265358979323846;
Char data type
■ Character data type allows its variable to store only a single character. The size of
the character is 1 byte. Range is -128 to 127 or 0 to 255 if ‘unsigned’ used before
char.
– char beta = ‘b’; char delta = ’D’;
Scope:
■ What is Scope: Scope refers to the visibility and lifetime of variables and functions
within a program.
Storage class
■ Every variable that is declared in a C program has its scope and lifetime. Storage
class allows us to determine a variable's scope, visibility, and lifetime.
■ Whenever we define a variable in the program, we also define its data type and its
storage class.
■ data type talks about the size and the binary representation of a variable inside the
memory whereas storage class tells us variable's scope, visibility, and lifetime.
Storage class
■ Every variable that is declared in a C program has its scope and lifetime. Storage
class allows us to determine a variable's scope, visibility, and lifetime.
■ Whenever we define a variable in the program, we also define its data type and its
storage class.
■ data type talks about the size and the binary representation of a variable inside the
memory whereas storage class tells us variable's scope, visibility, and lifetime.
Summary of Storage Classes in C
Auto storage class
■ Default storage class for all variables. No need to declare ‘auto’ explicitly.
■ When variable is of ‘auto’ storage class, variable is stored on RAM.
■ Scope and lifetime is limited to block only,
– int db_id = 24;
– char name = ‘z’;
– auto char version = ‘a’;
– float fraction;
Register storage class
extern variable is
■ extern is useful for declaring variables that declared in header file
needs to be visible to all source files that are dynamic.h and being
linked into given project. accessed in c file
■ A variable cannot be initialised in an extern dynamic.c
declaration, as no space is actually allocated
during the declaration.
volatile keyword
■ volatile tells the compiler that the variable is explicitly changeable, and
seemingly useless accesses of the variable (for instance, via pointers) should not be
optimized away.
■ In other words, only user can assign or reassign values of variable which is declared
as volatile and compiler can’t optimise or change value of given variable on its
own.
– volatile float currentTemperature = 40.2;