Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Hello world" in C without printf? [closed]

Tags:

c

Is it possible to write a "hello world" program in C without the use of the printf function? (while still keeping the program relatively at a few lines)

like image 726
user1869465 Avatar asked Feb 10 '13 04:02

user1869465


2 Answers

This should work:

int main (void)
{
    puts("Hello, World!");
    return 0;
}

Why don't you want to use printf? I can't think of any reason not to.

like image 142
Michael Dickens Avatar answered Nov 15 '22 02:11

Michael Dickens


Well, if we're going to include silly examples (yes, I'm looking at you, technosauraus), I'd go with:

#include <stdio.h>

void makeItSo (char *str) {
    if (*str == '\0') return;
    makeItSo (str + 1);
    putchar (*str);
}

int main (void) {
    makeItSo ("\ndlrow olleH");
    return 0;
}

Just don't do this for really long strings or you'll find out what Stack Overflow really means :-)

like image 39
paxdiablo Avatar answered Nov 15 '22 02:11

paxdiablo