GATE | GATE CS 2019 | Question 64
Consider the following C program:
#include<stdio.h> int main() { int a[] = {2, 4, 6, 8, 10}; int i, sum = 0, *b = a + 4; for (i = 0; i < 5; i++ ) sum = sum + (*b - i) - *(b - i); printf("%d\n", sum); return 0; } |
chevron_right
filter_none
The output of above C program is __________ .
Note: This was Numerical Type question.
(A) 10
(B) 8
(C) 6
(D) 3
Answer: (A)
Explanation:
#include<stdio.h> int main() { int a[] = {2, 4, 6, 8, 10}; int i, sum = 0, *b = a + 4; for (i = 0; i < 5; i++ ) sum = sum + (*b - i) - *(b - i); printf("%d\n", sum); return 0; } |
chevron_right
filter_none
Given, “for” loop will run from i=0 to 4.
i = 0 sum = 0+ 10 – 10 = 0 i = 1 sum = 0 + 9 – 8 = 1 i = 2 sum = 1 + 8 – 6 = 3 i = 3 sum = 3 + 7 – 4 = 6 i = 4 sum = 6 + 6 – 2 = 10
Now, loop terminate and value of sum (i.e., 10) will be printed.
So, The output of above C program is 10.
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 1999 | Question 36
- GATE | GATE CS Mock 2018 | Question 39
- Top 5 Topics for Each Section of GATE CS Syllabus
- How to prepare in Last 10 days to score high in GATE?
- Aptitude | GATE IT 2006 | Question 7
- Aptitude | GATE IT 2006 | Question 8
- GATE | GATE CS 2013 | Question 1
- GATE | GATE CS 2013 | Question 3
- GATE | GATE CS 2013 | Question 4
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 6
- GATE | GATE CS 2013 | Question 7
- GATE | GATE CS 2013 | Question 8
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 65



