Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

valid hu 7.1 Consider the following sequence of C/c++ statements, which are synt

ID: 3910293 • Letter: V

Question

valid hu 7.1 Consider the following sequence of C/c++ statements, which are syntactically but have no abl es) reasonable semantic interpretation (assuming that i and j have been declared as int var j-0: i3/j: for (i-1; 1>-1: i++) How are these situations handled when executed by your C/C++ system? Give other kinds (beyond those illustrated in the previous question) of C/C++ statements that are syntactically valid but whose meaning cannot be reasonably defined in the semantics of a programming language. 7.2

Explanation / Answer

7.1) i=3/j; This was syntactically correct but symantically wrong. Because the operation that we are using here is division by j (j=0). Anything that was divisible by 0 is infinite. So this was symantically incorrect.

These statements can be handled by using try catch block as follows.

try {
i = 3/j;
} catch (std::overflow_error e) {
std::cout << e.what() ;
}

7.2

Some examples which are syntactically correct but semantically wrong.

int i+j=k; // Semantic error (int k=i+j is correct)

int i=+j; // Semantic error (int i+=j is correct)