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 8605341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:48:24+00:00 2026-06-12T02:48:24+00:00

On my machine, the following program writes 1234 to it’s output. const char str[]

  • 0

On my machine, the following program writes 1234 to it’s output.

const char str[] = "1234";
printf("%c%c%c%c\n",
    (int) (0xff & (*(uint32_t*) str) >> 0),
    (int) (0xff & (*(uint32_t*) str) >> 8),
    (int) (0xff & (*(uint32_t*) str) >> 16),
    (int) (0xff & (*(uint32_t*) str) >> 24));

This implies that str is internally represented as 0x34333231, and the first byte str[0] represents the least significant 8 bits.

Does this mean str is encoded in little endian? And is the output of this program platform-dependent?

Also, is there a convenient way to use 1, 2, 4 and 8 character string literals in switch case statements? I can’t find any way to convert the strings to integers, as *(const uint32_t* const) "1234" is not a constant expression, and 0x34333231/0x31323334 might be platform dependent and must be notated in hexadecimal.

edit:

In other words, is 0xff & *(uint32_t*) str always equal to str[0]?

Eh, never mind, just realized it is and also why.

  • 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-12T02:48:26+00:00Added an answer on June 12, 2026 at 2:48 am

    Endianness refers to the order of bytes in a larger value. Strings are (at least in C and C++) an array of bytes so endianness doesn’t apply.

    You actually can do what you mention in the last paragraph using multicharacter literals, though it’s implementation defined exactly how it works and the string must be no longer than sizeof(int).

    C++ standard, §2.14.3/1 – Character literals

    (…) An ordinary character literal that contains more than one c-char is a multicharacter literal . A multicharacter literal has type int and implementation-defined value.

    For instance, 'abcd' is a value of type int with an implementation-defined value. This value probably would depend on endianness. Since it is an integer, you are allowed to switch on it.

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

Sidebar

Related Questions

The following C++ program crashes on my Windows XP machine with a message Abnormal
I meet following exception when I copy the whole program directoy to another machine.
I have the following program: ~/test> cat test.cc int main() { int i =
The output of the following program differs depending on whether I have IntelliJ compile
The following program always echoes machine-abc in the end: @echo Off set dropLoc=machine-abc IF
I ran the following program on little-endian [LE] machine [Linux, Intel processor]. I am
The attached program (see at the end), when executed, yields the following output: ..........
Please have a look at the following machine code ‎0111001101110100011100100110010101110011011100110110010101100100 This means something. I
I get the following results on my machine: Python 3.2.2 (default, Sep 4 2011,
I am following a tutorial in the book Machine Learning for Hackers by Drew

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.