Here are the possible ways.
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Hello World!\n");
// 1. Using Standard `printf` Function
printf("Hello World!\n");
// 2. Using `puts` Function
puts("Hello World!");
// 3. Using `write` System Call (Unix/Linux)
write(1, "Hello World!\n", 13);
// 4. Without Using Standard Library (Minimalist)
const char msg[] = "Hello World!\n";
for (int i = 0; msg[i] != '\0'; i++) {
putchar(msg[i]);
}
// 5. Using Function Pointer to `printf`
void (*print)(const char *, ...) = printf;
print("Hello World!\n");
// 6. Using Recursion
void printHello(int n) {
if (n == 0) return;
printf("Hello World!\n");
}
printHello(1);
// 7. Printing `Hello World!` Character by Character
char str[] = "Hello World!";
for(int i = 0; str[i] != '\0'; i++) {
putchar(str[i]);
}
putchar('\n');
// 8. Using Array of Function Pointers
void hello() {
printf("Hello World!\n");
}
void (*funcs[1])() = { hello };
funcs[0]();
return 0;
}
Advertisement
Advertisement
0 Comments