LESSON 6-Researved Keywords and Operators

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

KEYWORDS

IN
PROGRAMMING
STUDY THIS CODE
KEYWORDS
#include <stdio.h>
main()
{
int float;
float = 10;
printf( "Value of float = %d\n", float);
}
KEYWORDS
So far, we have covered two important
concepts called variables and their data
types.
We discussed how to use int, long, and
float to specify different data types.
We also learnt how to name the variables to
store different values.
KEYWORDS
Like int, long, and float, there are
many other keywords supported by C
programming language which we will
use for different purpose.
Different programming languages
provide different set of reserved
keywords,
KEYWORDS
There is one important &
common rule in all the
programming languages
that we cannot use a reserved
keyword to name our
variables.
KEYWORDS
What does this mean?
It means we cannot name our
variable like int or float
rather these keywords can
only be used to specify a
variable data type.
KEYWORDS
For example,
if you will try to use any
reserved keyword for the
purpose of variable name, then
you will get a syntax error.
KEYWORDS
#include <stdio.h>
main()
{
int float;
float = 10;
printf( "Value of float = %d\n", float);
}
KEYWORDS
When you compile the
above program, it produces
an error:
Programming Reserved Keywords

Refer to the table having


almost all the keywords
supported by C Programming
language:
 Pages 27 and 28 of the book
Programming Reserved Keywords

You cannot memorize all these keywords,


but I have listed them down for your
reference purpose and to explain the concept
of reserved keywords.
So just be careful while giving a name to
your variable, you should not use any
reserved keyword for that programming
language.
OPERATORS
OPERATORS
An operator in a programming language is a
symbol that tells the compiler or interpreter
to perform specific
mathematical,
relational or
logical operation and
produce final result.
OPERATORS
This lesson will explain the
concept of operators and
We will through the important
arithmetic and relational
operators available in C, Java,
and Python.
Arithmetic Operators
Computer programs are widely
used for mathematical
calculations.
We can write a computer program
which can do simple calculation
like adding two numbers (2 + 3).
Arithmetic Operators
We can also write a program, which can
solve a complex equation like
P(x) = x4 + 7x3 - 5x + 9.
If you have been even a poor student, you
must be aware that in first expression 2 and
3 are operands and + is an operator.
Similar concepts exist in Computer
Programming.
Arithmetic Operators
Take a look at the following
two examples:
2+3
P(x) = x4 + 7x3 - 5x + 9.
Arithmetic Operators
These two statements are called
arithmetic expressions in a
programming language.
and plus, minus used in these
expressions are called arithmetic
operators.
Arithmetic Operators
The values used in these
expressions like 2, 3 and x, etc.,
are called operands.
 In their simplest form, such
expressions produce numerical
results.
Arithmetic Operators
Similarly, a programming language provides
various arithmetic operators.
The following table lists( Refer to page 30)
down a few of the important arithmetic
operators available in C programming
language.
Arithmetic Operators
Following is a simple example of
Programming to understand the above
mathematical operators:
Refer to book page 31 for code
Use the arithmetic operators given and
write simple arithmetic code and print
them out.
Relational Operators
Relational Operators
Consider a situation where we
create two variables and assign
them some values as follows:
A = 20
B = 10
Relational Operators
Here, it is obvious that variable
A is greater than B in values.
So, we need the help of some
symbols to write such
expressions which are called
relational expressions.
Relational Operators

If we use C programming


language, then it will be written as
follows:

(A > B)
Relational Operators
Here, we used a symbol > and it is called a
relational operator
in their simplest form, they produce Boolean
results which means the result will be either
true or
false.
Similarly, a programming language provides
various relational operators.
Relational Operators
The table on (Page 32) lists down a
few of the important relational
operators available in C
programming language.
Assume variable A holds 10 and
variable B holds 20, then:
Relational Operators
Here, we will discuss one example
of C Programming which makes
use of if conditional statement.
Though this statement will be
discussed later in our next separate
lesson.
We use if statement to check a
condition and if the condition is true,
then the body of if statement is
executed, otherwise the body of if
statement is skipped.
Refer to page 33 for code
Logical Operators
Logical Operators
Logical operators are very
important in an
programming language and
they help us take decisions
based on certain conditions.
Logical Operators
Suppose we want to combine the
result of two conditions, then logical
AND
OR
logical operators help us in producing
the final result.
Logical Operators
The following table
shows(Refer to pg 34) all the
logical operators supported by
the C language.
Assume variable A holds 1 and
variable B holds 0, then:
Logical Operators
LAB ACTIVITY
Try the following example to
understand all the logical
operators available in C
programming language:
Refer to book pg 35
Operators in Java
Increment and decrement operators

C programming has two


operators increment ++ and
decrement -- to change the
value of an operand
(constant or variable) by 1.
Increment and decrement operators
Increment ++ increases the value by
1 whereas decrement -- decreases the
value by 1.
These two operators are unary
operators,
meaning they only operate on a
single operand.
Increment and decrement operators
#include <stdio.h>
int main()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;
printf("++a = %d \n", ++a);
printf("‐‐b = %d \n", ‐‐b);
printf("++c = %f \n", ++c);
printf("‐‐d = %f \n", ‐‐d);
return 0;
}
Answers to unary question
++a = 11
‐‐b = 99
++c = 11.5
++d = 99.5

You might also like