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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:18:24+00:00 2026-06-06T10:18:24+00:00

The following bit of code… void foo(char* x) { int i; int len =

  • 0

The following bit of code…

void foo(char* x)
{
        int i;
        int len = sizeof(x)/sizeof(x[0]);

        printf("len: %d\n", len);
        for(i=0; i<len; i++){
                printf("i: %d, v: %x\n", i, x[i]);
        }
}

…when called as:

        char bar[] = {0xDE, 0xAD, 0xBE, 0xEF};
        foo(bar);

…outputs:

len: 8
i: 0, v: ffffffde
i: 1, v: ffffffad
i: 2, v: ffffffbe
i: 3, v: ffffffef
i: 4, v: ffffffff
i: 5, v: 7f
i: 6, v: 0
i: 7, v: 0

Not exactly sure if it’s applicable to this but reading through similar posts on SO, it seems to be an alignment issue (I’m on a 64 bit machine).

Any pointers?

Thanks.

  • 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-06T10:18:26+00:00Added an answer on June 6, 2026 at 10:18 am

    This has nothing do to with alignment.

    int len = sizeof(x)/sizeof(x[0]);
    

    x is a pointer and not an array. sizeof (x) computes the size of the pointer which is 8 bytes on your 64-bit machine.

    Now it prints ffffffde insteas of de because of integer promotion (sign extension is performed). To avoid the ffffff you can use unsigned char type instead of char or cast the printf arguments to unsigned int like this:

    printf("i: %d, v: %x\n", i, (unsigned int) x[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bit of code in a method called by clicking the
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
I have the following bit of code: As a global variable: char *orderFiles[10]; And
I have the following bit of code which runs a SQL statement: int rowsEffected
Why does the following bit of code work in C: int res = pow(2,
Using the following bit of code: function Node(){ .... function foo(request){ for (var name
The following bit of code works great in everything but IE. In IE, the
The following bit of code breaks in the upgrade to jquery 1.4: $().mousemove( function
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
In the following bit of code, pointer values and pointer addresses differ as expected.

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.