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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:30:51+00:00 2026-05-13T12:30:51+00:00

#include <stdio.h> int main(void){ unsigned a[3][4] = { {2,23,6,7}, {8,5,1,4}, {12,15,3,9} }; printf(%u,*((int*)(((char*)a)+4))); return

  • 0
#include <stdio.h>

int main(void){
  unsigned a[3][4] = {
    {2,23,6,7},
    {8,5,1,4},
    {12,15,3,9}
 };
 printf("%u",*((int*)(((char*)a)+4)));
 return 0;
}

The output in my machine is the value at a[0][1] i.e 23.Could somebody explain how is this working ?

Edit: Rolling Back to old yucky code,exactly what was presented to me 😛

  • 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-05-13T12:30:51+00:00Added an answer on May 13, 2026 at 12:30 pm

    So you have your array in memory as so:

    2, 23, 6, 7, 8...
    

    What this does is cast the array to a char*, which lets you access individual bytes, and it points here:

    2, 23, 6, 7, 8...
    ^
    

    It then adds four bytes, moving it over to the next value (more on this later).

    2, 23, 6, 7, 8...
       ^
    

    Then it turns it into an int* and dereferences it, getting the value 23.


    There are technically three things wrong with this code.

    The first is that it assumes that an unsigned is 4 bytes in size. (Hence the + 4). But this isn’t necessarily true! Better would have been + sizeof(unsigned), ensuring correctness no matter what size unsigned happens to be.

    The second problem is the cast to int: the original array was unsigned, but the value is being cast to an int. There exists values in the unsigned range that int cannot represent (because in an int half of the range is in the negatives.) So if one of the values in the array was not representable as an int (meaning the value was greater than INT_MAX), you’d get the wrong value. Better would be to convert to unsigned*, to maintain the correct type.

    The last thing is the format specifier. The specifier for integers is %d, but the code uses %u, which is for unsigned integers. In effect, even though casting back to int* was wrong, printf is going to cast that value back into an unsigned*, restoring it’s integrity. By fixing problem two, problem three fixes itself.

    There is a hidden fourth problem: The code sucks. This may be for learning purposes, but yuck.

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

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are lots of versions of VBA, integrated in various… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer Craig Hockenberry from Twitteriffic fame will help you out. Stay… May 16, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer Ok.. it was stupid. I use stupid ″ instead of… May 16, 2026 at 5:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
I am confused with this program. #include <stdio.h> int main(void) { char* ptr=MET ADSD;
#include<stdio.h> void f(void) { int s = 0; s++; if(s == 10) return; f();
this program hangs after taking first argument:- #include <stdio.h> #include <conio.h> void ellip(char*,...); int
Let us say i have File1.c: #include<stdio.h> #includeFile2.c void test(void) { sum(1,2); } int
I managed to get a unsigned long int octets-representation (BE) by reading IPv4 methods,
Please suggest me a more efficient alternative to go about this Program #include <stdio.h>
Could the own heap space be readed? could the software be self modified in
i wrote the code but i dont get max value how to find max
I'm trying to write a little helper for Windows which eventually will accept a

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.