Consider the two C++ programs P1 and P2 shown below and two statements about them:
S1: P1 prints out 3
S2: P2 prints out 4:2 What can you say about S1 and S2?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. Only S1 is true.
Explanation
P1: f(i, &i, i) copies a = 0 → 1 locally, *b = 2 sets i = 2, and c is a reference to i, so c = 3 leaves i = 3: S1 is true. P2: f(a) binds d to a and sets a = 4, then returns a reference to b, which is assigned 5, so it prints 4:5: S2 is false.
More Programming Languages and Computer Graphics questions
- Consider the following recursive Java function f that takes two long arguments and returns a float value : public static float f(long m, lo…
- What does the following Java function perform? (Assume int occupies four bytes of storage) public static int f( int a) { // Pre-conditions…
- Which of the following HTML5 codes will affect the horizontal as well as vertical alignment of the table content?
- Consider the C/C++ function f() given below: void f(char w[]) { int x = strlen(w); // length of the string char c; for (int i = 0; i < x; i…
- The definitions in an XML document are said to be __________ when the tagging system and definitions in the DTD are all in compliance.
- Consider the JavaScript code: var y = "12"; function f() { var y = "6"; alert(this.y); function g() { alert(y); } g(); } f(); If M is the n…