Write a C program to print “ Tutorials Point ” without using a semicolon


To print any string without using a semicolon we need to find how the standard output work and why is semicolon used.

The semicolon is a end of line statement that is used to tell the program that the line is ended here. The standard print statement printf used here is a method of the standard io library. Let's dig deep into the printf() method.

int printf(const char *format , ...)

This method returns an integer and has a set of arguments format and … . The format is a string that is printed in the output screen. And the … is the additional number of arguments that are given to the function based on the string.

The funnctions return the total number of character that is to be printed on the screen.

Using this we can find ways to bypass the use of end of line statement while printing the statement. We can use some statements that do not require the end of LINE statement to execute like the for loop. We can use this to print are set a statement without using the semicolon.

There are several methods by which we can print statement without using the semicolon;

1.Using the if condition

#include<stdio.h>
int main() {
   if (printf("Tutorials point") )
   { }
}

2.Using the switch statement

#include<stdio.h>
int main() {
   switch (printf("Tutorials point") )
   { }
}

3.Using the while loop

#include<stdio.h>
int main() {
   while (printf("Tutorials point") )
   { }
}

4. Using the macros

#include<stdio.h>
#define Out printf("Tutorials point")
int main() {
   switch (out)
   { }
}
raja
Published on 09-Aug-2019 15:36:55
Advertisements