C program to print characters without using format specifiers

In this article we will see how we can print some characters without using any kind of format specifiers. The format specifiers in C are %d, %f, %c etc. These are used to print characters and numbers in C using the printf() function.

Here we will see another way to print characters without using %c format specifier. This can be done by putting ASCII values directly in hexadecimal form using escape sequences.

Syntax

printf("\xHH");  // HH is hexadecimal ASCII value

Method 1: Using Hexadecimal Escape Sequences

The \x escape sequence allows us to specify characters by their hexadecimal ASCII values −

#include <stdio.h>

int main() {
    printf("\x41<br>");  // 41 is ASCII of 'A' in Hex
    printf("\x52<br>");  // 52 is ASCII of 'R' in Hex  
    printf("\x69<br>");  // 69 is ASCII of 'i' in Hex
    return 0;
}
A
R
i

Method 2: Using Octal Escape Sequences

We can also use octal escape sequences with backslash followed by octal digits −

#include <stdio.h>

int main() {
    printf("\101<br>");  // 101 is ASCII of 'A' in Octal
    printf("\122<br>");  // 122 is ASCII of 'R' in Octal
    printf("\151<br>");  // 151 is ASCII of 'i' in Octal
    return 0;
}
A
R
i

Method 3: Using putchar() Function

The putchar() function can print characters using their ASCII decimal values −

#include <stdio.h>

int main() {
    putchar(65);   // 65 is ASCII of 'A' in Decimal
    putchar('<br>');
    putchar(82);   // 82 is ASCII of 'R' in Decimal
    putchar('<br>');
    putchar(105);  // 105 is ASCII of 'i' in Decimal
    putchar('<br>');
    return 0;
}
A
R
i

Key Points

  • Hexadecimal escape sequences use \xHH format where HH is the hex value
  • Octal escape sequences use \nnn format where nnn is the octal value
  • putchar() accepts decimal ASCII values directly

Conclusion

Characters can be printed without format specifiers using escape sequences (\x for hex, \ for octal) or the putchar() function with ASCII values. These methods provide direct control over character output.

Updated on: 2026-03-15T10:06:04+05:30

886 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements