Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:29:50+00:00 2026-06-15T06:29:50+00:00

Why does printing a null char (‘\0’, 0) with %s prints the (null) string

  • 0

Why does printing a null char (‘\0’, 0) with %s prints the “(null)” string actually?

Like this code:

char null_byte = '\0';
printf("null_byte: %s\n", null_byte);

…printing:

null_byte: (null)

…and it even runs without errors under Valgrind, all I get is the compiler warning warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat] (note: I’m using gcc 4.6.3 on 32bit Ubuntu)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:29:56+00:00Added an answer on June 15, 2026 at 6:29 am

    It’s undefined behavior, but it happens that on your implementation:

    • the int value of 0 that you pass is read by %s as a null pointer
    • the handling of %s by printf has special-case code to identify a null pointer and print (null).

    Neither of those is required by the standard. The part that is required[*], is that a char used in varargs is passed as an int.

    [*] Well, it’s required given that on your implementation all values of char can be represented as int. If you were on some funny implementation where char is unsigned and the same width as int, it would be passed as unsigned int. I think that funny implementation would conform to the standard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example of what my code looks like: void *a = NULL;
Basically what I mean is like this: List<String[]> routes = (List<String[]>)application.getAttribute(routes); For the above
In the following code, I copy a string in to a char* str, which
Why does this code produce seemingly random behavior, std::cout << ( thePointerIsGood = (
I'm using the following code... var result = document.evaluate(expr,context,null,9,null); When printing the result I
In this code. public class Test { public static void testFun(String str) { if
I have an array of chars like this one: char arr[3]=hi; cout << arr;//
Does JavaFX 2.0 supports printing? I have a text area from which I take
The following method does its job but keeps printing a warning also, im pretty
Does anyone know if there is a way to generate different code in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.