Write a program to print ‘Tutorials Point’ without using a semicolon in C

CServer Side ProgrammingProgramming

In this problem, we have to write a program that will print ‘Tutorials Point ’ without using a semicolon.

We all know that to end a statement in c semicolon is necessary. And print statement will be executed when a semicolon is added at the end.

So, for printing ‘Tutorials point’ without a semicolon, we will have to first learn about the printf method in c. in actually returns an integer which is the count of total number of characters that are required to be printed.

Syntax

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

The method can accept n number of arguments. The first will be the string to be printed and it returns the total number of characters to be printed.

Using this knowledge about the printf method we can print ‘tutorials point’ without using a semicolon by using the print statement inside the condition of a conditional statement, which will execute an empty block of code. Also, we can use macros and while loop for completing this task.

Let’s see each of them,

Program to print using if statement,

Example

 Live Demo

#include<stdio.h>
int main(){
   if (!printf("Tutorails Point") )
   { }
}

Output

Tutorails Point

Program to print using switch statement,

Example

 Live Demo

#include<stdio.h>
int main(){
   switch (!printf("Tutorails Point") )
   { }
}

Output

Tutorails Point

Program to print using while loop,

Example

 Live Demo

#include<stdio.h>
int main(){
   while(!printf("Tutorails Point") )
   { }
}

Output

Tutorails Point

Program to print using macros,

Example

 Live Demo

#include<stdio.h>
#define printstr printf("Tutorails Point")
int main(){
   if (!printstr)
   { }
}

Output

Tutorails Point
raja
Published on 15-Jul-2020 06:37:19
Advertisements