ALLInterview.com :: Home Page KalAajKal.com
 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                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
#include<stdio.h>
void fun(int);
int main()
{
int a;
a=3;
fun(a);
printf("\n");
return 0;
}
void fun(int i)
{
  if(n>0)
  {
    fun(--n);
    printf("%d",n);
    fun(--n);
   }
}  the answer is 0 1 2 0..someone explain how the code is
executed..?
 Question Submitted By :: Geetha_raj2007
I also faced this Question!!     Rank Answer Posted By  
 
  Re: #include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?
Answer
# 1
for example :
Here a is three(3).
 
calling  fun(3) in main function.
 FUN(3) {
    calling fun(2) {
	calling fun(1)  {
  	    calling fun(0) {
		N>0 found.
            }
	    printed 0				
            calling second fun(-1) {
		N>0 found. 
            }
        }
	printed 1					
        calling second fun(0) {
       	    N>0 found.
        }
    }
     printed 2		
     calling second fun(1) {
	 calling fun(0) { 
	     N>0 found.
         } 
	 printed 0		
         calling second fun(-1) {
 	     N>0 found.
         } 
     }
 }
 
Is This Answer Correct ?    3 Yes 1 No
Siva Kumar
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
How to swap two variables, without using third variable ? HCL48
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }  1
how to return a multiple value from a function? Wipro2
How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”) HCL1
int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p  1
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }  1
void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }  1
main() { printf("%d", out); } int out=100;  1
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }  1
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }  1
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above HCL1
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }  1
main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } }  1
What is the hidden bug with the following statement? assert(val++ != 0);  1
main() { char a[4]="HELLO"; printf("%s",a); }  1
void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above HCL1
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }  1
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?  1
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0 HCL1
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
 
For more C Code 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 © 2007  ALLInterview.com.  All Rights Reserved.

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