Consider the following C program:#include<stdio.h>
int main() {
int x[] = {2,4,6,8,10};
int a, b = 0, *y = x + 4;
for (a = 0; a < 5; a++) {
b = b + (*y - a) - *(y - a);
}
printf("%d\n", b);
return 0;
}What will be the output of the above C program?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: D. 10
Explanation
*y = 10. For a = 0..4 the term (10 − a) − x[4 − a] is 10−10 = 0, 9−8 = 1, 8−6 = 2, 7−4 = 3, 6−2 = 4. Sum = 10.More Programming Languages and Computer Graphics questions
- Which of the following are TRUE about constructors in C++? (A) A constructor can be overloaded. (B) A constructor does not have a return ty…
- What is the output of the following program?#include<stdio.h> void f1(char *x, char *y) { char *t1; t1 = x; x = y; y = t1; } void f2(char *…
- Which of the following C++ statements correctly declares an abstract class?
- Consider the following C++ program:#include<iostream> using namespace std; void swap(int &x, int &y) { int temp = x; x = y; y = temp; } int…
- What is the output of the code given below?#include<iostream> using namespace std; class Base { public: Base() { cout << "Base Const"; } vi…
- Consider the following C code:#include<stdio.h> int temp = 0; int fun(int x, int y) { int z; temp++; if (y == 3) return (x*x*x); else { z =…