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

Answers were Sorted based on User's Feedback



consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / naksh @tcs

Answer is 6;

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

Is This Answer Correct ?    17 Yes 2 No

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / yogendra jain

6

Is This Answer Correct ?    15 Yes 2 No

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / vignesh1988i

the final value of x is 6

Is This Answer Correct ?    10 Yes 1 No

consider the following C code main() { int i=3,x; while(i>0) { x=fu..

Answer / manishsoni

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 ?    5 Yes 0 No

Post New Answer

More C Interview Questions

What is the use of linkage in c language?

0 Answers  


do ne body have any idea about the salary for the we r going to have interview. yup .. u got it right ..i m talking abt NIC.

1 Answers  


#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }

0 Answers   Wilco,


Differentiate between functions getch() and getche().

0 Answers  


What does extern mean in a function declaration?

4 Answers  






What is hashing in c language?

0 Answers  


What is clrscr in c?

0 Answers  


explain what is a newline escape sequence?

0 Answers  


9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?

4 Answers   L&T,


What is 1f in c?

0 Answers  


Can U write a C-program to print the size of a data type without using the sizeof() operator? Explain how it works inside ?

3 Answers   HCL, TCS,


write a progam to compare the string using switch case?

1 Answers  


Categories