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 does the function toupper() do?

0 Answers  


WAP to accept first name,middle name & last name of a student display its initials?

5 Answers   AITH, NIIT,


write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

0 Answers  


can you explain in brief what is "r+" mode in a file... i know that it si used to read and modify rhe existing content.... but explalanation about the file pointer in "r+" mode i wann to know???????????

2 Answers   Cognizant,


Can you assign a different address to an array tag?

0 Answers  






Explain bit masking in c?

0 Answers  


a direct address that identifies a location by means of its displacement from a base address or segment a) absolute address b) relative address c) relative mode d) absolute mode

0 Answers  


What is meant by operator precedence?

0 Answers  


Why do we need a structure?

0 Answers  


What are header files in c programming?

0 Answers  


What are the parts of c program?

0 Answers  


struct node {struct node*temp,*new} prinf("%d",sizeof(struct node));

2 Answers  


Categories