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 3 of 6.
Manikanth said:
1 decade ago
Void type cannot return anything to the main function.
Vinoth said:
1 decade ago
But my question void means it does not return anything so how the values pass in to main function?
Prashant kumar said:
1 decade ago
Everything is fine for option B, but function "change" is not declared it will show error I think!
Sujju said:
1 decade ago
#include<stdio.h>
int main(){
int a=5,b=10,c=15;
int *arr[]={&a,&b,&c};
printf("%d",*arr[1]);
return 0;
What is the o/p of above program?
int main(){
int a=5,b=10,c=15;
int *arr[]={&a,&b,&c};
printf("%d",*arr[1]);
return 0;
What is the o/p of above program?
Pankaj Singh said:
1 decade ago
*[b+1] = *[b+i]+5;
*[a+1] = *[b+0]+5;
a[1] = b[0]+5;
a[1] = 2+5;
a[1] = 7;
Now it will continuous till the b[i] = 10.
So a[1] = 15;
For other it will remain same.
2 15 6 8 10.
a[0] a[1] a[2] a[3] a[4].
*[a+1] = *[b+0]+5;
a[1] = b[0]+5;
a[1] = 2+5;
a[1] = 7;
Now it will continuous till the b[i] = 10.
So a[1] = 15;
For other it will remain same.
2 15 6 8 10.
a[0] a[1] a[2] a[3] a[4].
Manoj said:
1 decade ago
Change the position of a[i] with respect to the position of the second element of the array.
Pratik patel said:
1 decade ago
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5; /*( b[1]=b[i]+5 ) . */
End time loop.
b[1] = b[5]+5.
b[1] = 10+5.
b[1] = 15.
Ans = 2, 15, 6, 8, 10.
*(b+1) = *(b+i)+5; /*( b[1]=b[i]+5 ) . */
End time loop.
b[1] = b[5]+5.
b[1] = 10+5.
b[1] = 15.
Ans = 2, 15, 6, 8, 10.
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).
XYZ said:
1 decade ago
*(a+i)=a[i]. that should give the address of a[i] right? why is it giving the value?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers