Exercise 3-5 (Precedence)

Chapter_3     Exercise_3-4     Recursion Increment     Exercise_3-6







Exercise 3-5     TCP1, p. 227


Exercise 3-5. Write a program that evaluates the two expressions in the Subsection labeled "Precedence" (Section "Introduction to Operators").




Precedence.cpp     TCP1, p. 138-139         download


#include <iostream>
using std::cout;
using std::endl;

int main()
{
int x = 1, y = 2, z = 3;

cout << x + y - 2/2 + z << endl;
cout << x + (y - 2)/(2 + z) << endl;

return 0;
}
/*
g++ Precedence.cpp -o Precedence
./Precedence
5
1
*/





Note:  See also Chapter_2, Sec. 2.12, on Kernighan_and_Ritchie blog.









Chapter_3     Exercise_3-4     Recursion BACK_TO_TOP Increment     Exercise_3-6



Comments

Popular posts from this blog

Contents