Saturday, January 16

are you C programmer enough?

could you solve this problem?

Someday, Mr. Willy gave me a site that consist of Programming Interview Questions (because our basic was an IT programmer). Lots of challenge cases in there, of course I love it. And I tried to solve some cases too.

This is a simple one, that always made me enthusiastic..
[based on C language programming]
What's the "condition" so that the following code snippet prints both HelloWorld ?
if "condition"
printf ("Hello");
printf ("World");

Output : HelloWorld


  1. #include "stdio.h"

    void main()
    { if(printf("Hello") && 0)

  2. gee,
    bayu could solve this easily..
    actually, lots of our friends can't solve this case
    because we didn't think about "function"

  3. Thank you...

    but I don't know is that the best solution or not, because we just hard code the conditions to printf the word "Hello"...

    Not really refer to the statement inside the if block... :P

  4. yeah, i know that :D

    Mr. Nico also solved like that (with PHP), but with OR operator one
    if( 0 || printf("Hello") )

    remember that PHP had a shortcut method, then
    if( 0 || printf("Hello") ) != if( printf("Hello") || 0 )

    and my junior, Lina'08, done well too
    if( !printf("Hello") )

    i think, Lina's code was great....

  5. Actually all have same approach...
    whenever that function successfully executed, it will return true...

    so what we have to do is simply make it become false in order to run the "else" part...

    It can be done in many ways... :)

  6. by the way, why don't you follow (back link) my blogspot...??

  7. hu'uh....
    after i understand it, i realized that we never give "this" to our students
    what a pity >,<

    ~~~ sesaaaaat ~~~

  8. Actually I gave them this material, especially in programming that involving php.

    we often use checker function to test a variable exist or not that returning a boolean value. And You already know why, because php doesn't need variable declaration.... :D

    /* already logged in */


  9. heihooo, we talk about C, right? :p
    i means, we never give "this" to them in algorithm & programming

    do you ever think like this:
    *is printf() a function? void or non-void one??
    *could we do like this if( printf(..) )?
    *then, what is the real result of printf(..)? output in system?? boolean?? others??

    hmmmmmm, i must try to be open-minded....

  10. I already know it quite long time ago...
    I think it is little bit advance for them to dig it deeper in algorithm class..

    some of them still confuse whether their custom function return a value or not...
    *even it is their own function... they made it by themselves... (-_-!)

    but actually they can read it in the help / manual, what built in function are returning value, and return what... :P

  11. yeap, they still don't understand about function itself.. even theirs :P

    hope that i could think like you
    because autodidact is not the best way to learn too
    sharing could help autodidact's one

  12. whenever you can't find the answer, just ask somebody...
    It also part of the learning...

    I asked my seniors too in here several times in my self learning...

    They are so awesome... :P

  13. i'm just an ordinary person
    and i've great people around me

    lee was very blessed..

  14. Nice...

    Like indonesia wise word...

    Shy to ask, You'll get lost on the road... :P