logo

CuriousTab

CuriousTab

Discussion


Home Technical Questions Programming Comments

  • Question
  • Point out the error, if any, in the following program. main() { int ( *p )() = fun; ( *P ) (); } fun () { Printf ( "\nLoud and clear" ); }


  • Correct Answer
  • Here we are initalising the function pointer p to the address of the function fun() But during this initialisation the function has not been defined Hence an error To eliminate this error add the prototype of the fun() before declaration of p, as shown below: extern int fun(); or simply int fun(); 


  • Programming problems


    Search Results


    • 1. What is the difference between the following declarations? extern int fun(); int fun();
    • Discuss
    • 2. What would be the output of the following program? main() { extern int i; i = 20; printf( "%d", sizeof(i) ); }
    • Discuss
    • 3. The output of the code below is #include int *m() { int *p = 5; return p; } void main() { int *k = m(); printf("%d", k); }

    • Options
    • A. 5
    • B. Junk value
    • C. 0
    • D. Error
    • Discuss
    • 4. What is the output of this C code? #include void m() { printf("hi"); } void main() { m(); }

    • Options
    • A. hi
    • B. Run time error
    • C. None
    • D. Varies
    • Discuss
    • 5. What will be output of following c code? void main() { struct india { char c; float d; }; struct world { int a[3]; char b; struct india orissa; }; struct world st ={{1,2,3},'P','q',1.4}; clrscr(); printf("%dt%ct%ct%f",st.a[1],st.b,st.orissa.c,st.orissa.d); getch(); }
    • Discuss
    • 6. Point out the error, if any, in the while loop. main() { int i = 1; while () { printf ( "%d", i++); if (i >10) break ; } }
    • Discuss
    • 7. Point out the error, if any, in the following program. main() { int i = 4, j = 2; switch(i) { case 1 : printf (''\n To err is human, to forgive is against company policy."); break; case j : printf (''\n if you have nothing to do, don't do it here."); break; } }
    • Discuss
    • 8. What would be the output of the following program? main() { static int a[20]; int i = 0; a[i] = i++; printf ("\n%d%d%d", a[0], a[1], i); }
    • Discuss
    • 9. What would be the output of the following program? main() { int i=2 ; printf ("\n%d%d", ++i, ++i ); }
    • Discuss
    • 10. In the following code in which order the functions would be called? a = ( f1 ( 23,14 ) * f2 ( 12/4) ) + f3() ;
    • Discuss


    Comments

    There are no comments.

Enter a new Comment