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

In C programming, semicolons are statement terminators that mark the end of each statement. However, it's possible to print text without using semicolons by leveraging control structures and the return value of printf().

Syntax

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

The printf() function returns an integer representing the number of characters printed. This return value can be used in conditional expressions within control structures that don't require semicolons.

Method 1: Using if Statement

The if statement can evaluate the return value of printf() without requiring a semicolon −

#include <stdio.h>

int main() {
    if (printf("Tutorials Point"))
    { }
    return 0;
}
Tutorials Point

Method 2: Using switch Statement

A switch statement can also evaluate printf()'s return value without semicolons −

#include <stdio.h>

int main() {
    switch (printf("Tutorials Point"))
    { }
    return 0;
}
Tutorials Point

Method 3: Using while Loop

A while loop executes the printf() once and then exits because the condition becomes false after printing −

#include <stdio.h>

int main() {
    while (!printf("Tutorials Point"))
    { }
    return 0;
}
Tutorials Point

Method 4: Using Macros

Macros can be defined without semicolons and used within control structures −

#include <stdio.h>

#define PRINT printf("Tutorials Point")

int main() {
    if (PRINT)
    { }
    return 0;
}
Tutorials Point

How It Works

  • printf() returns the number of characters successfully printed
  • Control structures evaluate expressions without requiring statement terminators
  • The return value of printf() serves as the condition for these control structures
  • Empty code blocks { } prevent infinite loops or unwanted behavior

Conclusion

These methods demonstrate C's flexibility by using control structures and function return values to bypass semicolon requirements. While creative, such techniques are typically used for educational purposes rather than production code.

Updated on: 2026-03-15T11:29:35+05:30

332 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements