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;
}
Discussion:
53 comments Page 6 of 6.
Prithviraj said:
1 decade ago
Answer is [B]. 2, 15, 6, 8, 10.
Because in the above code there are few mistakes.
1) There is no link between main program and function. i.e there is no prototype.
2) Return type is void.
Because in the above code there are few mistakes.
1) There is no link between main program and function. i.e there is no prototype.
2) Return type is void.
XYZ said:
1 decade ago
*(a+i)=a[i]. that should give the address of a[i] right? why is it giving the value?
Vignesh said:
1 decade ago
Answer must be option a function definition is perform and return the value to the function call so it should be a option (A).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers