Loading in 5 sec....

Computer Programming CS F111PowerPoint Presentation

Computer Programming CS F111

- 144 Views
- Uploaded on
- Presentation posted in: General

Computer Programming CS F111

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Vishal Gupta

Department of Computer Science and Information Systems

Birla Institute of Technology and Science

Pilani Campus, Pilani

Agenda:

Expression Evaluation: Precedence & Associativity

- Operators have rules that are used to determine how expressions are evaluated.
- Precedence and associativity deal with the evaluation order within expressions.
- Precedencerules specify the order in which operators of different precedence level are evaluated.
- Associativityrules decides the order in which multiple occurrences of the same level operator are applied.

- First, parenthesized sub expression from left to right are evaluated.
- If parentheses are nested, the evaluation begins with the innermost sub expression.
- The precedence rule is applied in determining the order of application of operators in evaluating sub-expressions.
- The associativity rule is applied when two or more operators of the same precedence level appear in a sub expression.

1) z = 2*3/4+4/4+8-2+5/7

z = ??

2) y = 4/5*6+2/7+4

y = ??

3) Let inta,b;

float c,d;

a=5;b=7;

c=4.0;d=3.0;

Then compute

x = a/b*(c+d)/a-b+c/d

Example

What is the output of the following piece of code ??

#include <stdio.h>

int main (void)

{

int a, b=21, c=7;

a = ++c – b-- % 5;

printf (“Value of a = %d, b = %d, c = %d”,a, b, c);

}

Priority can be overruled by parenthesis. With this expression inside parenthesis are evaluated first so

(1+2)*3 gives 9

Thank You