C program to print a string without using semicolon in the printf

C program to print a string without using semicolon in the printf :

In this tutorial, we will learn how to print a string using printf and without using a semicolon. We will show you different approaches below :

Using a for loop :

#include<stdio.h>

int main(){
	int i;
	for(i=0 ; !printf("Hello World\n");i++){

	}
}

This program will print the string Hello World. Because, the loop will first try to run, since the value of !printf() is always false, it will print the string and exit the loop.

Using a while loop :

#include<stdio.h>

int main(){
	while(!printf("Hello World\n")){

	}
}

Using if :

#include<stdio.h>

int main(){
	if(!printf("Hello World\n")){

	}
}

Using switch :

#include<stdio.h>

int main(){
	switch(printf("Hello World\n")){

	}
}

This question is asked mainly in programming interviews. Each of these above process uses the same concept .