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

  • Home
  • SEARCH
  • 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 9244061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:56:18+00:00 2026-06-18T08:56:18+00:00

The below program tests for Little/Big endian on intel processor. Actually little endian is

  • 0

The below program tests for Little/Big endian on intel processor. Actually little endian is correct output. First I am casting int to char* and accessing its value without initialization to int *.I am not understanding second part of output. Here int pointer is casted to char *. So why is not int pointer not changed its alignment to char *?

00000000 00000000 00000011 01111111 = 895
0        0         3       127

int main() {
    int num = 895;
    if(*(char *)&num == 127)
    {
        printf("\nLittle-Endian\n");
    }
    else
    {
        printf("Big-Endian\n");
    }

    int *p = (char *)&num ;
    if(*p == 127)
    {
        printf("\nLittle-Endian\n");
    }
    else
    {
        printf("Big-Endian\n");
    }
    printf("%d\n",*p);
}

o/p

Little-Endian
Big-Endian
895
  • 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-18T08:56:19+00:00Added an answer on June 18, 2026 at 8:56 am
    1. The first half of your program using this comparison:

      if(*(char *)&num == 127)
      

      looks fine.

    2. The second half of your program contains this assignment:

      int *p = (char *)&num ;
      

      Which isn’t valid code. You can’t convert pointer types without an explicit cast. In this case, your compiler might be letting you get away with it, but strictly speaking, it’s incorrect. This line should read:

      int *p = (int *)(char *)#
      

      or simply this equivalent statement:

      int *p = #
      

      From this example, I’m sure you can see why your second test doesn’t work the way you’d like it to – you’re still operating on the whole int, not on the single byte you were interested in. If you made p a char *, it would work the way you expected:

      char *p = (char *)#
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below program contains two show() functions in parent and child classes, but first show()
In the below program,i am not getting values from printf . #include<stdio.h> int main()
I have a little confusion in the following two statements. The below program is
The little test program below prints out: And SS Number IS =3039 I would
I have a Enumeration as shown in below program public class Test { public
The below program calculates 2 raised to the power n without using any loop,runtime
I have the below program that will move files from one directory to other.
In this below program i am printing the contents of the div when i
The program below prints the following data: Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1 Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2 Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0 Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2 Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0 Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3 Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
The program below prints: my name is:null my name is:null Someclass static init AFAIK

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.