05 operators, structure
TRANSCRIPT
-
7/30/2019 05 Operators, Structure
1/17
Introduction to C Programming
Operators, programming structures,
functions, strings
-
7/30/2019 05 Operators, Structure
2/17
Module Code and Module Title Title of Slides
Statements
A statementis a Specification of an action to
be taken by the computer as the program
executes.
Each C statement must end with thepunctuator/ separator semicolon (;).
For Example:-
c= a+b; But, some of the statements should not
end with semicolon.
For Example, while ( I
-
7/30/2019 05 Operators, Structure
3/17
Module Code and Module Title Title of Slides
Expressions
An Expression is a Combination of both
Operators and Operands.
For Example:-
city_tax = taxrate * gross_income;
c= a + b;
area = 2 * pi * r;
-
7/30/2019 05 Operators, Structure
4/17
Module Code and Module Title Title of Slides
Operators
Operators act on Operands.
Basically, by the operands, the operators
are divided into three types:
Unary Operator
Binary Operator Ternary Operator
-
7/30/2019 05 Operators, Structure
5/17
Module Code and Module Title Title of Slides
Operators
Unary Operator:
An Operator that requires one Operand
is Unary Operator. For Example,
(-p)
p++--i
-
7/30/2019 05 Operators, Structure
6/17
Module Code and Module Title Title of Slides
Operators
Ternary Operator:
An Operator that acts on three Operands
Otherwise, called as Conditional Operator(?:)
For Example,c = (a > b)? a : b;
-
7/30/2019 05 Operators, Structure
7/17Module Code and Module Title Title of Slides
Operators
Binary Operator:
An Operator that requires two
Operands. For Example,
a+b
p-qx/y
-
7/30/2019 05 Operators, Structure
8/17Module Code and Module Title Title of Slides
Operators
Generally Operators are classified as,
Arithmetic Operators
Relational Operators
Logical Operators
-
7/30/2019 05 Operators, Structure
9/17Module Code and Module Title Title of Slides
Operators
Arithmetic Operators:
Operator Action
- Substraction,unary minus + Addition
* Multiplication
/ Division% Modulus
-- Decrement
++ Increment
-
7/30/2019 05 Operators, Structure
10/17Module Code and Module Title Title of Slides
Operators
Relational Operators:
Operator Action
> Greater than
>= Greater than or equal
< Less than
-
7/30/2019 05 Operators, Structure
11/17Module Code and Module Title Title of Slides
Operators
Logical Operators:
Operator Action
&& AND
|| OR
! NOT
-
7/30/2019 05 Operators, Structure
12/17Module Code and Module Title Title of Slides
Precedence and Order of Evaluation
Operators Associativity
( ) left to right
! ++ -- right to left
* / % left to right
+ - left to right
< >= left to right= = != left to right
-
7/30/2019 05 Operators, Structure
13/17Module Code and Module Title Title of Slides
Precedence and Order of Evaluation
Operators Associativity
&& left to right
| | left to right
?: right to left
= += -= *= /= %= right to left
-
7/30/2019 05 Operators, Structure
14/17Module Code and Module Title Title of Slides
Standard Output function printf()
The Syntax for theprintf() function is,
printf(Format Control String);
printf(Format Control String, print list);
For Example :-
printf(Enter your age:);
printf(%d, age);
printf(Your age of birth is %d, yob );
-
7/30/2019 05 Operators, Structure
15/17Module Code and Module Title Title of Slides
Standard Input function scanf()
The Syntax for the scanf() function is,
scanf (Format Control String, print list);
Example 1:-
printf(Enter your age:);
scanf(%d,&age);
printf(Type your weight in inches:);
scanf(%d,&weight);
-
7/30/2019 05 Operators, Structure
16/17Module Code and Module Title Title of Slides
Standard Input function scanf()
Example 2:-
Using Characters:
char a;
scanf(%c,&a);printf(The character is ..%c,a);
Input of String variables:
char name[10];scanf(%s, name);
Gets the charactersuntil the occurrence of
the white space/blank
-
7/30/2019 05 Operators, Structure
17/17Module Code and Module Title Title of Slides
Quick Review Question
Categorize each of the following as either hardware
or software:
a. CPU
b. compiler
c. ALU
d. Preprocessor Directivese. Input unit
f. A word processor program