Monday, April 13, 2009

lets print hello world in C language

Here's the snippet

int main() {
if (/*your code goes here*/) {
printf("hello");
} else {
printf("world");
}
return 0;
}

Try printing "helloworld" by just filling in the condition in the if statement ?

Hint:
Ever wondered what printf returns? ;)

2 comments:

  1. if (printf("hello") == 99) {
    printf("hello");
    } else {
    printf("world");
    }
    ------------------------------------------------
    Heres a crazy one
    ------------------------------------------------
    int *ptr;
    if (printf("helloworld") == 10? *ptr==10 :false) {
    printf("hello");
    } else {
    printf("world");
    }

    ReplyDelete
  2. lol. you do know that ptr would be initialized to junk.
    I'm not sure y u're doing what you're doing.

    Anyways, you'd end up printing either helloworldhello or helloworldworld :) [without the smiley of course.

    ReplyDelete