Welcome Guest | Sign in | Register
Loops - Discussion Page For Q.10467 | C Programming Questions and Answers | C Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Loops > Questions and Answers

Q: What will be the output of the following program?
main( )
{
int gyan[] = { 10, 20, 30, 40, 50 };
int i, *ptr ;
ptr = gyan;
for ( i = 0 ; i <4 ; i++ )
{
fun(ptr++);
printf ( â??\n%dâ??, *ptr ) ;
}
}
void fun(int *i)
{
*i = *i + 1;
}
A. 11 21 31 41 B. 20 30 40 50
C. 21 31 41 51 D. 10 20 30 40

Answer and Explanation

Answer:20 30 40 50

Explanation:
When we call the function fun() the current address contained by it will get passed and then it get incremented. For ex. If the base address is of the array is 100 then successive elements are stored at 102, 104, 106 and 108.
In the first call 100 get passed to fun() and ptr becomes 102. Now the called function fun() manipulates the value stored at 100 and in the main() function values at the address contained by ptr are getting printed.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.