std::putchar(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::putchar(3) πŸ’–

okay so bestie, welcome to the std::putchar page from the C++ Standard Libary manual (yes, that’s the manual name, we’re keeping it exactly as it is πŸ’…). This whole page is about writing one character to stdout, and honestly? iconic.


✨ NAME ✨

  • std::putchar β€” std::putchar, the tiny one-character writer with main character energy πŸŽ€

✨ Synopsis ✨

Defined in header <cstdio>:

int putchar( int ch );

Writes a character ch to stdout. Internally, the character is converted to unsigned char just before being written. No cap, that’s literally the whole vibe.

Equivalent to std::putc(ch, stdout). periodt.


🌸 Parameters 🌸

  • ch β€” the character to be written. That’s it, bestie. That’s the whole parameter list. 🫢

πŸ’… Return value πŸ’…

On success, returns the written character. Slay ✨

On failure, returns EOF and sets the error indicator (see std::ferror()) on stdout. Big yikes, but that’s the deal 😭.


πŸ”₯ Example πŸ”₯

// Run this code

        #include <cstdio>

        int main()
        {
            for (char c = 'a'; c != 'z'; ++c)
                std::putchar(c);

            // putchar return value is not equal to the argument
            int r = 0x1024;
            std::printf("\nr = 0x%x\n", r);
            r = std::putchar(r);
            std::printf("\nr = 0x%x\n", r);
        }

πŸ¦‹ Possible output πŸ¦‹

abcdefghijklmnopqrstuvwxy
r = 0x1024
$
r = 0x24

🌈 See also 🌈

  • fputc writes a character to a file stream
  • putc (function)
  • C documentation for putchar

mwah πŸ’‹ β€” source: http://cppreference.com, version 2024.06.10, page std::putchar(3). byeee 🫢

πŸ“¦ where this page comes from