ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
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
Google
   
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther 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
Answer
# 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
Answer
# 2
Answer is 6;

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
Answer
# 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
Answer
# 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]
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
why java is called as a purely oops language. TVS2
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 HCL8
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-Soft4
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? Zensar2
Write a routine that prints out a 2-D array in spiral order! Lucent1
Hai why 'c' is the middle language  4
main() { int i=400,j=300; printf("%d..%d"); } ME13
What is the output of the following program #include<stdio.h> main() { int i=0; fork(); printf("%d",i++); fork(); printf("%d",i++); fork(); wait(); } ADITI8
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com