0% found this document useful (0 votes)
11 views20 pages

Week-2 - Lecture-1 Constants Variables Keywords

The document is a lecture on Introduction to Programming (CSE-202) by Kazi Hassan Robin, focusing on constants, variables, and keywords in the C programming language. It explains the definitions and types of constants, the rules for constructing them, and the concept of variables and keywords, including their significance in programming. Additionally, it covers the differences between compilers and interpreters, and introduces the Integrated Development Environment (IDE) for software development.

Uploaded by

shahmumsunny00
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)
11 views20 pages

Week-2 - Lecture-1 Constants Variables Keywords

The document is a lecture on Introduction to Programming (CSE-202) by Kazi Hassan Robin, focusing on constants, variables, and keywords in the C programming language. It explains the definitions and types of constants, the rules for constructing them, and the concept of variables and keywords, including their significance in programming. Additionally, it covers the differences between compilers and interpreters, and introduces the Integrated Development Environment (IDE) for software development.

Uploaded by

shahmumsunny00
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
You are on page 1/ 20

CSE-202

Introduction to
Programming
C O N D U C T E D B Y:
KAZI HASSAN ROBIN,

A S S O C I AT E P R O F E S S O R ,

D E P T. O F C O M P U T E R S C I E N C E & E N G I N E E R I N G

E - M A I L : R O B I N 1 @ C S E .W U B . E D U . B D

PHONE: 01820547352

Introduction to Programming | CSE-202


Week-2; Lecture 1
Introduction to Constants, Variables and Keywords

The alphabets, numbers and special symbols


when properly combined form constants,
variables and keywords in C programming
language. It is important to understand the
core concept and purpose of Constants,
Variables and Keywords in C. These are the
fundamentals that will help you to
understand the complex concepts of C that
will come later.
Constants in C (cont’d)

As its name suggests constants are the values which will never change
during the execution of program. Sounds confusing? Let’s try to make
things more clear with a simple example.
In the above picture (left) we have stored the constant value 3 at x
location. The name of that location is x. It’s a variable. We can also store
another value at x location, as we have done that in picture (right), where
we have stored the constant value 5 at x location.
Here X = variable (location or memory address name) and 3, 5 = constant
Constants in C (cont’d)
There are two type of Constants
1.Primary constants
2.Secondary constants (We will learn them later)
At this stage we will only discuss primary constants. Primary constants
are of three types.
1.Integer constants
2.Real constants
3.Character constants

Let’s discuss them one by one.


Constants in C (cont’d)
Definition of Primary Constants
Integer Constant
It will contain only integers. Remember an integer constant will never
contain any decimal point. Eg: 1, 2, -43 etc.
Character Constant
It is single (remember) alphabet, number or any special symbol which is
enclosed in an inverted commas. Eg: ‘+’, ‘1’, ‘a’, etc.
Real Constant or Floating Point Constant
A real constant may have any digit but it must contain one decimal point.
Eg: 1.22, -54.5, 3432.13
Rules for Constructing Integer Constants

 An integer constant must have at least one digit.


 It must not have a decimal point
 It can be either positive or negative.
 If no sign precedes an integer constant it is assumed to be
positive.
 No commas or blanks are allowed within an integer
constant.
Rules for Constructing Real Constants

 A real constant must have at least one digit.


 It must have a decimal point.
 It could be either positive or negative.
 Default sign is positive.
 No commas or blanks are allowed within a real constant.
Rules for Constructing Character Constants
 A character constant is a single alphabet, a single digit or a
single special symbol enclosed within single inverted
commas.
 Both the inverted commas should point to the left. For
example, ’A’ is a valid character constant whereas ‘A’ is not.
 The maximum length of a character constant can be 1
character.
Variables in C
A variable is nothing but a name given to a storage area that
our programs can manipulate. Each variable in C has a
specific type, which determines the size and layout of the
variable's memory; the range of values that can be stored
within that memory; and the set of operations that can be
applied to the variable.
The name of a variable can be composed of letters, digits,
and the underscore character. It must begin with either a
letter or an underscore. Upper and lowercase letters are
distinct because C is case-sensitive.
Common types of variables in C
Defining variables in C
A variable definition tells the compiler where and how much
storage to create for the variable. A variable definition specifies a
data type and contains a list of one or more variables of that type
as follows −
type variable_list;
Here, type must be a valid C data type including char, int,
float, double etc. and variable_list may consist of one or
more identifier names separated by commas. Some valid
declara ons are shown here −
Int i, j, k; char c, ch;
Float f, salary; double d;
Keywords in C
Keywords are those words whose meaning is already defined by
Compiler. In C, we have 32 keywords, which have their predefined
meaning and cannot be used as a variable name. These words are
also known as “reserved words”. It is good practice to avoid using
these keywords as variable name. Here they are:
Lvalues and Rvalues in C
There are two kinds of expressions in C −
•lvalue − Expressions that refer to a memory loca on are
called "lvalue" expressions. An lvalue may appear as
either the left-hand or right-hand side of an assignment.
•rvalue − The term rvalue refers to a data value that is
stored at some address in memory. An rvalue is an
expression that cannot have a value assigned to it which
means an rvalue may appear on the right-hand side but
not on the left-hand side of an assignment.
Lvalues and Rvalues in C (cont’d)
Variables are lvalues and so they may appear on the left-
hand side of an assignment. Numeric literals are rvalues and
so they may not be assigned and cannot appear on the left-
hand side. Take a look at the following valid and invalid
statements-
int g = 20; // valid statement
10 = 20; // invalid statement; would generate
compile-time error
Getting Introduced with
Integrated Development Environment (IDE)
An integrated development environment (IDE) is a
software application that provides comprehensive facilities
to computer programmers for software development. An
IDE normally consists of:
a source code editor
build automation tools
a debugger
Some IDEs contain compiler, interpreter, or both,
Compiler vs Interpreter
Compiler and interpreter, both basically serve the
same purpose. They convert one level of language
to another level.
A compiler converts the high level instructions into
machine language while an interpreter converts the
high level instruction into some intermediate form
and after that, the instruction is executed.
Differences of Compiler and Interpreter
A complier converts the high level instruction into machine language
while an interpreter converts the high level instruction into an
intermediate form.
Before execution, entire program is executed by the compiler whereas
after translating the first line, an interpreter then executes it and so on.
List of errors is created by the compiler after the compilation process
while an interpreter stops translating after the first error.
An independent executable file is created by the compiler whereas
interpreter is required by an interpreted program each time.
Thank you
Thank you very much for listening to
this lecture. I will be arranging a quiz
next week based on these two lectures
that I have provided. I will suggest you
to further study on the topics that I
have discussed to understand them
thoroughly.
Best of luck.

You might also like