1. Given the code snippet below, what is the value of c that is printed?
int a = 3, b = 4, c;
a = 3; b = 4;
a *= b;
c = ++a * b--;
cout << "c is: " << c ;
Answer choices: 52, 32, 42
Ans: C is 52 (Option 1)
Explanation: a*=b means a=a*b = a=3*4 = 12
now, c= ++a*b--
since ++a means pre-increment so a's value is first incremented then multiplication occurs, so a becomes 13, b=4. As b-- is there which means post-decrement means after the operation will be performed then b's value will be reduced, hence 13*4= 52
So output value of c is 52.
1. Given the code snippet below, what is the value of c that is printed? int...
51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = # num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...
What is wrong with the following code snippet? int main() { int width = 10; height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; } The code snippet uses an uninitialized variable. The code snippet uses an undefined variable. The code snippet attempts to assign a decimal value to an integer variable. The code snippet attempts to assign an integer value to a decimal variable.
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
Consider the following code snippet. What will be printed by *ptr and ptr after the lines shown. Explain with screenshots. int a[4] = { 8, 3, 5, 6}; int *ptr = a; ptr ++;
What number will the following code snippet print? int numbers[8] = { 34, 42, 6, 11, 29, 1, 89, 62}; cout << numbers[7];
help What is the output of the code snippet below? int [ ] [ ] numarray = t 8, 7, 6, 1 0, 0, 0 li System.out.print (numarray [0] [0]) System.out.print (numary System.out.print (numarray to1 to array 1] to]); a) 00 b) 87 c) 80 d) 08
1. How many times does the message, “Hello” get printed out by the code segment below? int count = 0; while (count < 32) { printf(“Hello\n”); count = count+4; } 2. What is the value of sum at the end of the following code segment? int sum = 0, index; for (index = 0; index < 5; index++) sum += 5; Group of answer choices
Write this code in c++ and screen shot the code 2. Given the code below: int vals t1 (4.7,11). valPtr valPtr-vals What is the output of the following statements, if it is an address, indicate that: a. cout (1valPtr) F c. cout << (valPtr2); e. cout <<*(valPtr0) cout << "True" cout << "False" cout << "True" cout << "False" cout << "True" cout << "False", ㄱ Hip else g. if (valPtr&valPtr [1]) else h. if (valPtr (4] &valPtr [1]) else
What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1. int fly = 5; int x; if (fly-- > 5) x = 5; else x = 2; if (x++ > 3) cout << x; cout << fly << endl; 2. int i = 0; bool b = i == 0 || i++ > 0; if (!b) cout << i << endl; else cout...
Explain what each line of the following snippet of code does: int *ptr; ptr = new int; *ptr = 10; cout << ptr << ' ' << &ptr << ' ' << *ptr; delete ptr; cout << ptr << ' ' << &ptr << ' ' << *ptr;