Home  >  Article  >  Backend Development  >  Write a program to print "Tutorials Point" in C language without using semicolon

Write a program to print "Tutorials Point" in C language without using semicolon

王林
王林forward
2023-09-15 10:41:071230browse

编写一个在C语言中不使用分号打印“Tutorials Point”的程序

In this problem we have to write a program to print "Tutorials Point" without using semicolon.

We all know that it is necessary to end a statement with a semicolon. The print statement will be executed when a semicolon is added at the end.

So, to print the "tutorial point" without semicolon, we first need to understand the printf method in c. in actually returns an integer, which is the total number of characters that need to be printed.

Syntax

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

This method can accept n parameters. The first is the string to be printed, which returns the total number of characters to be printed.

Using the knowledge about the printf method we can print the "tutorial point" without using a semicolon by using a print statement inside the conditional statement, which will execute an empty code piece. Alternatively, we can use macros and while loops to accomplish this task.

Let’s take a look at them,

Program using if statement for printing, p>

Example

Real-time demonstration

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

Output

Tutorails Point

A program that uses switch statements to print,

Example

Real-time demonstration

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

Output

Tutorails Point

Program using while loop printing,

Example

Online demonstration

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

Output

Tutorails Point

Program using macros for printing,

Example

Real-time demonstration

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

Output

Tutorails Point

The above is the detailed content of Write a program to print "Tutorials Point" in C language without using semicolon. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete