Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
 Do you have a collection of Interview Questions and interested to share with us!! Please send that collection to along with your userid / name. ThanQ

 Categories  >>  Software  >>  Programming Languages  >>  C

 C Interview Questions C++ Interview Questions VC++ Interview Questions Delphi Interview Questions Programming Languages AllOther Interview Questions
Question
consider the following C code
main()
{
int i=3,x;
while(i>0)
{
x=func(i);
i--;
}
int func(int n)
{
static sum=0;
sum=sum+n;
return(sum);
}
the final value of x is
Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By

Re: consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is
# 1
6
 Is This Answer Correct ? 13 Yes 1 No
Yogendra Jain

Re: consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is
# 2

Sum being the static variale will retain its value state
between he function calls.

 Is This Answer Correct ? 14 Yes 1 No
Naksh @tcs

Re: consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is
# 3
the final value of x is 6
 Is This Answer Correct ? 9 Yes 1 No
Vignesh1988i

Re: consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is
# 4
we know that the static can't change its value but in
functions:-
"This inside a function static variable retains its value
during various calls."
{
static sum=0; at i=3;sum=0+3;save or retains sum=3
sum=sum+n; at i=2;sum=3+2:save or retains sum=5
return(sum); at i=1;sum=5+1;save or retains sum=6
}
so the final value is 6;

if here we declare sum as auto type then it didn't retains
its value or print 1;sum=0+1;

 Is This Answer Correct ? 4 Yes 0 No
Manishsoni
[Gyan Corporation]

  Question Asked @ Answers Other C Interview Questions why java is called as a purely oops language. TVS 2 Write a pro-gramme to determine whether the number is even or odd? 1 write a program to generate 1st n fibonacci prime number 11 what are the static variables HCL 8 how to find string length wihtout using c function? 6 what are the difference between ANSI C and Let Us c and Turbo C LG-Soft 4 what is the difference between c and java? 1 write a function that accepts an array A with n elements and array B with n-1 elements. Find the missing one in array B,with an optimized manner? Zensar 2 Write a routine that prints out a 2-D array in spiral order! Lucent 1 Hai why 'c' is the middle language 4 main() { int i=400,j=300; printf("%d..%d"); } ME 13 What is the output of the following program #include main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); } ADITI 8 For more C Interview Questions Click Here