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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:22:28+00:00 2026-06-03T15:22:28+00:00

As far as I know, in C programming language, an array is stored on

  • 0

As far as I know, in C programming language, an array is stored on the memory element by element. (i.e., element 0, element 1, element 2, … , element n). I’m trying to see that with the following code:

unsigned char a[] = { '\1' , '\2', '\3' ,'\4' };  
printf("%d\n", (int*) a);

Since unsigned char is 1 byte and an integer is 4 bytes; I thought it has to print the value:

00000001 00000010 00000011 00000100 = 2^2 + 2^8 + 2^9 + 2^17 + 2^24 = 16909060

However, when I run this program, it generates different results for every trials.

What am I missing here?

  • 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-03T15:22:29+00:00Added an answer on June 3, 2026 at 3:22 pm

    You probably want to use *(int *)a, otherwise you’re just printing an address.

    However, this will invoke implementation-defined behaviour:

    • You will get a different result depending on the endianness of your platform.
    • Depending on the platform, the char array may not be properly aligned to be read as an int.
    • The compiler may perform funky optimizations based on assumptions that you will never read the char array through an int * – you are breaking what are known as the strict aliasing rules.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(for the D programming language) I've been struggling trying to initialise an associative array
As far as I know,any programming language which doesn't require to write type annotations
I'm new to object oriented programming and flash. As far as I know, global
As far as I know document.getElementById('myId') will only look for HTML elements that are
In any programming language, I can trace any function and know which function is
assuming that I know nothing about everything and that I'm starting in programming TODAY
I am new to the C programming language and trying to improve by solving
Let's assume for the moment that C++ is not a functional programming language. If
I'm quite new to that functional programming paradigm, but so far I like it.
I'm not a Natural Language Programming student, yet I know it's not trivial strcmp(n1,n2).

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.