C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 22)
22.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int i, a[] = {2, 4, 6, 8, 10};
    change(a, 5);
    for(i=0; i<=4; i++)
        printf("%d, ", a[i]);
    return 0;
}
void change(int *b, int n)
{
    int i;
    for(i=0; i<n; i++)
        *(b+1) = *(b+i)+5;
}
7, 9, 11, 13, 15
2, 15, 6, 8, 10
2 4 6 8 10
3, 1, -1, -3, -5
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
52 comments Page 6 of 6.

Sarada said:   1 decade ago
Each time when I valuse increases in the change function it will update in * (b+1) i.e. , first it will be 7 then it changes to 9 then it changes again to 11, then 13, 15 finally.

Shilpa said:   2 decades ago
When the function is called..during the first pass through the loop..
*(a+1)=*(a+0)+5..this becomes 7..we then repalce 4 by 7..similar;y through all the passes.

We ultimately get 2 15 6 8 10


Post your comments here:

Your comments will be displayed after verification.