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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:41:20+00:00 2026-06-13T01:41:20+00:00

I’m running this example program and I’m suppossed to be able to tell from

  • 0

I’m running this example program and I’m suppossed to be able to tell from the output what machine type it is. I’m certain it’s from inspecting one or two values but how should I perform this inspection?

/* pointers.c - Test pointers
 * Written 2012 by F Lundevall
 * Copyright abandoned. This file is in the public domain.
 *
 * To make this program work on as many systems as possible,
 * addresses are converted to unsigned long when printed.
 * The 'l' in formatting-codes %ld and %lx means a long operand. */

#include <stdio.h>
#include <stdlib.h>

int * ip; /* Declare a pointer to int, a.k.a. int pointer. */
char * cp; /* Pointer to char, a.k.a. char pointer. */

/* Declare fp as a pointer to function, where that function
 * has one parameter of type int and returns an int.
 * Use cdecl to get the syntax right, http://cdecl.org/ */
int ( *fp )( int );

int val1 = 111111;
int val2 = 222222;

int ia[ 17 ]; /* Declare an array of 17 ints, numbered 0 through 16. */
char ca[ 17 ]; /* Declare an array of 17 chars. */

int fun( int parm )
{
  printf( "Function fun called with parameter %d\n", parm );
  return( parm + 1 );
}

/* Main function. */
int main()
{
  printf( "Message PT.01 from pointers.c: Hello, pointy World!\n" );

  /* Do some assignments. */
  ip = &val1;
  cp = &val2; /* The compiler should warn you about this. */
  fp = fun;

  ia[ 0 ] = 11; /* First element. */
  ia[ 1 ] = 17;
  ia[ 2 ] = 3;
  ia[ 16 ] = 58; /* Last element. */

  ca[ 0 ] = 11; /* First element. */
  ca[ 1 ] = 17;
  ca[ 2 ] = 3;
  ca[ 16 ] = 58; /* Last element. */

  printf( "PT.02: val1: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val1, val1, val1 );
  printf( "PT.03: val2: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val2, val2, val2 );
  printf( "PT.04: ip: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &ip, (long) ip, (long) ip );
  printf( "PT.05: Dereference pointer ip and we find: %d \n", *ip );
  printf( "PT.06: cp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &cp, (long) cp, (long) cp );
  printf( "PT.07: Dereference pointer cp and we find: %d \n", *cp );

  *ip = 1234;
  printf( "\nPT.08: Executed *ip = 1234; \n" );
  printf( "PT.09: val1: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val1, val1, val1 );
  printf( "PT.10: ip: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &ip, (long) ip, (long) ip );
  printf( "PT.11: Dereference pointer ip and we find: %d \n", *ip );
  printf( "PT.12: val1: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val1, val1, val1 );

  *cp = 1234; /* The compiler should warn you about this. */
  printf( "\nPT.13: Executed *cp = 1234; \n" );
  printf( "PT.14: val2: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val2, val2, val2 );
  printf( "PT.15: cp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &cp, (long) cp, (long) cp );
  printf( "PT.16: Dereference pointer cp and we find: %d \n", *cp );
  printf( "PT.17: val2: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val2, val2, val2 );

  ip = ia;
  printf( "\nPT.18: Executed ip = ia; \n" );
  printf( "PT.19: ia[0]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ia[0], ia[0], ia[0] );
  printf( "PT.20: ia[1]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ia[1], ia[1], ia[1] );
  printf( "PT.21: ip: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &ip, (long) ip, (long) ip );
  printf( "PT.22: Dereference pointer ip and we find: %d \n", *ip );

  ip = ip + 1; /* add 1 to pointer */
  printf( "\nPT.23: Executed ip = ip + 1; \n" );
  printf( "PT.24: ip: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &ip, (long) ip, (long) ip );
  printf( "PT.25: Dereference pointer ip and we find: %d \n", *ip );

  cp = ca;
  printf( "\nPT.26: Executed cp = ca; \n" );
  printf( "PT.27: ca[0]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ca[0], ca[0], ca[0] );
  printf( "PT.28: ca[1]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ca[1], ca[1], ca[1] );
  printf( "PT.29: cp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &cp, (long) cp, (long) cp );
  printf( "PT.30: Dereference pointer cp and we find: %d \n", *cp );

  cp = cp + 1; /* add 1 to pointer */
  printf( "\nPT.31: Executed cp = cp + 1; \n" );
  printf( "PT.32: cp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &cp, (long) cp, (long) cp );
  printf( "PT.33: Dereference pointer cp and we find: %d \n", *cp );

  ip = ca; /* The compiler should warn you about this. */
  printf( "\nPT.34: Executed ip = ca; \n" );
  printf( "PT.35: ca[0]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ca[0], ca[0], ca[0] );
  printf( "PT.36: ca[1]: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &ca[1], ca[1], ca[1] );
  printf( "PT.37: ip: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &ip, (long) ip, (long) ip );
  printf( "PT.38: Dereference pointer ip and we find: %d \n", *ip );

  cp = ia; /* The compiler should warn you about this. */
  printf( "\nPT.39: Executed cp = ia; \n" );
  printf( "PT.40: cp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &cp, (long) cp, (long) cp );
  printf( "PT.41: Dereference pointer cp and we find: %d \n", *cp );

  printf( "\nPT.42: fp: stored at %lx (hex); value is %ld (dec), %lx (hex)\n",
          (long) &fp, (long) fp, (long) fp );
  printf( "PT.43: Dereference fp and see what happens.\n" );
  val1 = (*fp)(42);
  printf( "PT.44: Executed val1 = (*fp)(42); \n" );
  printf( "PT.45: val1: stored at %lx (hex); value is %d (dec), %x (hex)\n",
          (long) &val1, val1, val1 );

  return( 0 );
}

Output

Message PT.01 from pointers.c: Hello, pointy World!
PT.02: val1: stored at 21e50 (hex); value is 111111 (dec), 1b207 (hex)
PT.03: val2: stored at 21e54 (hex); value is 222222 (dec), 3640e (hex)
PT.04: ip: stored at 21eb8 (hex); value is 138832 (dec), 21e50 (hex)
PT.05: Dereference pointer ip and we find: 111111
PT.06: cp: stored at 21e6c (hex); value is 138836 (dec), 21e54 (hex)
PT.07: Dereference pointer cp and we find: 0

PT.08: Executed *ip = 1234;
PT.09: val1: stored at 21e50 (hex); value is 1234 (dec), 4d2 (hex)
PT.10: ip: stored at 21eb8 (hex); value is 138832 (dec), 21e50 (hex)
PT.11: Dereference pointer ip and we find: 1234
PT.12: val1: stored at 21e50 (hex); value is 1234 (dec), 4d2 (hex)

PT.13: Executed *cp = 1234;
PT.14: val2: stored at 21e54 (hex); value is -771529714 (dec), d203640e (hex)
PT.15: cp: stored at 21e6c (hex); value is 138836 (dec), 21e54 (hex)
PT.16: Dereference pointer cp and we find: -46
PT.17: val2: stored at 21e54 (hex); value is -771529714 (dec), d203640e (hex)

PT.18: Executed ip = ia;
PT.19: ia[0]: stored at 21e74 (hex); value is 11 (dec), b (hex)
PT.20: ia[1]: stored at 21e78 (hex); value is 17 (dec), 11 (hex)
PT.21: ip: stored at 21eb8 (hex); value is 138868 (dec), 21e74 (hex)
PT.22: Dereference pointer ip and we find: 11

PT.23: Executed ip = ip + 1;
PT.24: ip: stored at 21eb8 (hex); value is 138872 (dec), 21e78 (hex)
PT.25: Dereference pointer ip and we find: 17

PT.26: Executed cp = ca;
PT.27: ca[0]: stored at 21e58 (hex); value is 11 (dec), b (hex)
PT.28: ca[1]: stored at 21e59 (hex); value is 17 (dec), 11 (hex)
PT.29: cp: stored at 21e6c (hex); value is 138840 (dec), 21e58 (hex)
PT.30: Dereference pointer cp and we find: 11

PT.31: Executed cp = cp + 1;
PT.32: cp: stored at 21e6c (hex); value is 138841 (dec), 21e59 (hex)
PT.33: Dereference pointer cp and we find: 17

PT.34: Executed ip = ca;
PT.35: ca[0]: stored at 21e58 (hex); value is 11 (dec), b (hex)
PT.36: ca[1]: stored at 21e59 (hex); value is 17 (dec), 11 (hex)
PT.37: ip: stored at 21eb8 (hex); value is 138840 (dec), 21e58 (hex)
PT.38: Dereference pointer ip and we find: 185664256

PT.39: Executed cp = ia;
PT.40: cp: stored at 21e6c (hex); value is 138868 (dec), 21e74 (hex)
PT.41: Dereference pointer cp and we find: 0

PT.42: fp: stored at 21e70 (hex); value is 69288 (dec), 10ea8 (hex)
PT.43: Dereference fp and see what happens.
Function fun called with parameter 42
PT.44: Executed val1 = (*fp)(42);
PT.45: val1: stored at 21e50 (hex); value is 43 (dec), 2b (hex)
  • 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-13T01:41:21+00:00Added an answer on June 13, 2026 at 1:41 am

    Why not just

    unsigned short u = 0xABCD;
    if ( *(const char *)&u == 0xAB )
       /*big endian*/;
    else
       /*little endian*/;
    

    Here’s why it works: in big endian architectures, the most significant byte has the lowest address of all bytes in a variable (of primitive type), IOW the most significant byte comes first. In little endian architectures it is the opposite: the least significant byte comes first. This piece of code just checks whether the byte with the lowest address contains the most significant byte of the number or not.

    More on endianness here

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of 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.