Objectives. To understand what variables areinitialization/garbage valuesnaming conventionsTo learn about the frequently used data typesTo understand the components of an assignment Statementsarithmetic expressionsTo learn about frequently used operators,operator precedence. VARIABLES. Var

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use only and may not be sold or licensed nor shared on other sites. SlideServe reserves the right to change this policy at anytime.While downloading, If for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

We can use Scientific Notation to represent real numbers that are very large or very small in value.

The letters e or E is used to represent times 10 to the power.

Example:

1.23 x 10 5is represented in C as 1.23e5or 1.23e+5or 1.23E5

1 x 10 -9is represented in C as 1e-9

Data Types and Sizes : (Continued)

Character : ( char )

Characters constants are usually used enclosed single quotes

Example: ‘A’ , ‘7’,

Only one byte of memory location is used by a character variable.

In ASCII code is used to represent uniquely any one of the available 255 characters

Example:

A is represented by decimal 65 or

8-bit binary 0 1 0 0 0 0 0 1

Data Types and Sizes : (Continued)

Categories of characters :

Alphabetic Letters :

( Upper case : ‘A’ , ‘B’, …….. ‘Z’ )

( Lower case : ‘a’ , ‘b’, …….. ‘z’ )

Numeric digits

( ‘1’,’2’,’3’,…………,’9’,’0’ )

Special Characters

( blank, ‘+’,’#’,’-‘,’_’,……..)

Control Characters

( ‘\n’ , ‘\t’ , ……. )

Assignment Statements

The ‘=‘ sign is an assignment operator.

Assignment statements replace old values of the variables with the new ones

An assignment statement assigns a value or a computational result to a variable.

Example

cnt= 1; sum = 0;

ch= ‘Y’;

sum = sum + 1; avg = sum / cnt;

stores values 1 and 0 to cnt and sum.

stores character ‘Y’ to ch

stores computational results to sum and avg

Expressions

Arithmetic Expressions involve arithmetic operators such as *,+,-,/,%:

Example : a * 5 + b % 4

Relational Expressions involve relational operators that compare two values such as >,<,== etc:

Example: a > b

Logical Expressions involve the logical andandor operators && and || and are used to combine relational expressions:

Example: ( a > b && c == 7 )

Arithmetic Expressions

In the Assignment Statement:

M = a * 5 + b % 4 ;

The expression to the right of the assignment operator ( = ) involves an arithmetic operation that combines arithmetic operands with arithmetic operators.

The most commonly used arithmetic operators are:

Addition (+) Operator

Subtraction (-) Operator

multiplication (*) Operator

division (/) Operator

remainder (%) Operator

For real or integer numbers

For integer numbers only

Operator Precedence Rules

Arithmetic expressions inside parentheses are executed first (left to right).

Unary operators ( minus signs and plus signs) are executed before multiplications, divisions and remainder operations.

Additions and subtractions are executed last.

parentheses

-ve and +ve signs

Mult. Div., and mod.

Add and subtract

Operator Precedence Rules:Examples

? =3 + 5* 4

Evaluated as 3 +(5*4) and the result is 23

? = 8 / (5 – 2)

Evaluated as 8 /3 and the result is 2

? = 8 + 12 % 5

Evaluated as 8 +(12%5) and the result is 10

? = 6 * 5 / 2 + 2

Evaluated as ( (6*5)/2)+ 2 and the result is 17

? = 9 – 4 + 2 * 6

Evaluated as 9 – 4 + (2*6) and the result is 17

? = 1 + 2 * (3 + 4)

Evaluated as 1 +(2 * (3+4)) and the result is 15

? = 5 * 2 + 9 % 4

Evaluated as (5*2) + (9 % 4) and the result is 11

? = 5 * 2 % ( 7 – 4)

Evaluated as (5 * 2)%(7 – 4) and the result is 1

That’s it for now!Next Lecture: More on variables, data types and expressions