Home > Backend Development > C++ > body text

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

王林
Release: 2023-09-15 10:41:07
forward
1297 people have browsed it

编写一个在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, ...)
Copy after login

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,

Example

Real-time demonstration

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

Output

Tutorails Point
Copy after login
Copy after login
Copy after login
Copy after login

A program that uses switch statements to print,

Example

Real-time demonstration

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

Output

Tutorails Point
Copy after login
Copy after login
Copy after login
Copy after login

Program using while loop printing,

Example

Online demonstration

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

Output

Tutorails Point
Copy after login
Copy after login
Copy after login
Copy after login

Program using macros for printing,

Example

Real-time demonstration

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

Output

Tutorails Point
Copy after login
Copy after login
Copy after login
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template