Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (a) (12%) You are given the following C-like code. int foo (int *p) { } *p = 1; return 2; int bar (int

  

4. (a) (12%) You are given the following C-like code. int foo (int *p) { } *p = 1; return 2; int bar (int *p) { } *p = 3; return 4; int main() { } int x = 10, y; y=x+foo (&x) + bar (&x); // Statement A There are at least three ways to evaluate the expression in statement A that results in variable y taking three different values. Briefly elaborate the three ways and state the value of y after each way of evaluation. (b) (5%) Write a function in C that has no functional side effect but is not referential transparent. Your function cannot have any print statements. State the semantics of your function. (c) (4%) In C or C++, evaluating the expression a=a++ produces undefined behavior. Give a reason to justify this design.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Management Theory and Practice

Authors: Eugene Brigham, Michael Ehrhardt, Jerome Gessaroli, Richard Nason

2nd Canadian edition

176517308, 978-0176517304

More Books

Students also viewed these Computer Network questions