Write a C program to print hello world without using semicolon. It’s an interesting problem, As in C code every line is terminated with a semicolon. So, how do we write a c program to print hello world without using semicolon. This problem is also important in terms of interview.
Programming Objective Question
C Program to Print Hello World without Using Semicolon
Let’s solve this problem. In C, you can’t directly write a statement without using a semicolon. But you can use condition to print hello world without using a semicolon. Seems confusing, let’s write a code.
1 2 3 4 5 6 7 8 9 10 11 |
#include <stdio.h> void main() { /* Print Hello World. */ if( printf("Hello World!") ) { } } |
In this program, I have not used a semicolon and we have printed hello world successfully without using any semicolon in our program.
Swap two numbers using call by reference
Swap two numbers using a third variable
C, C++ Programming questions for practice.
While Loop to Print Hello World without using Semicolon
In this example, we use while loop to write a program to print hello world without using a semicolon.
1 2 3 4 5 6 7 8 9 10 |
#include <stdio.h> int main(void) { while (!printf("hello world")) { } return 0; } |
Switch Statement to Print Hello World without using Semicolon
1 2 3 4 5 6 7 8 9 10 |
#include <stdio.h> int main(void) { switch(printf("Hello world")) { } return 0; } |