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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:10:38+00:00 2026-06-12T03:10:38+00:00

I have following code int main() { int arr[3] = {2, 3}; char *p;

  • 0

I have following code

int main()
{
    int arr[3] = {2, 3};
    char *p;
    p = arr;
    p = (char *)((int*)(p));
    printf("%d, ", *p);
    p++;
    p = (int*)(p+1);
    printf("%d", *p);
    return 0;
}

o/p-2,0

but I want to know how it is printing 0 in second printf ,I know all stuffs about little-endian as in memory of 4 byte integer how these elements are stored, as follows

00000010 00000000 0000000 00000000 00000011 00000000 00000000 00000000

so, during the first printf we got 2 as answer but during second printf the pointer is at second byte which is 0 but it is now a integer pointer but how it is printing 0,as it has to check for upto 4 bytes of memory then it has to print the whole data upto 4 byte.
I thought will be 3 as upto 4 byte it will print.

what i want is how the integer data is printing by printf,can any one tell this.

  • 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-12T03:10:39+00:00Added an answer on June 12, 2026 at 3:10 am

    The type of the pointer p does not change with either of the two: p = (char *)((int*)(p)); p = (int*)(p+1);.

    It still remains a pointer to a char.

    The cast only works to alter values (or types) in expressions. It applies to copies of values extracted from variables but does not modify those variables. Once the expression is over, the cast is gone with the value copy it was associated with.

    Example:

    signed char c = -1;
    int i;
    i = (unsigned char)c;
    

    Here the value of c, -1, is converted/cast to the type unsigned char. If chars are 8-bit, the result of (unsigned char)-1 is 255 and this value is of type unsigned char, which then gets converted to int and assigned to i.

    c does not change anyhow in the above process.

    Example 2:

    unsigned u = 0x55AA;
    unsigned* pu = &u;
    unsigned char* pc = (unsigned char*)pu;
    

    Here pu is converted/cast to type pointer to unsigned char. That conversion does not modify the variable pu, it only changes a copy of its value. And here it just changes the type of the copy, not the actual address, contained in the pointer variable. And then this copy of the address is assigned to pc. The cast is needed to avoid compiler warnings/errors, because the compiler has all the rights to “wonder” what is going on here and if there might be a programming mistake.

    Now both pu and pc point to the same location, the beginning of the variable u. But they have different types, one points to an unsigned char and the other, to an unsigned int.

    And so if you dereference pu and pc, you’ll get different values and those will be of different types as well.

    Likewise, if you do pointer arithmetic on the two pointers, for example, adding 1 to each, they will advance to point to different locations in memory. pu+1 will point to the location right after the end of u and pc+1 will point to the 2nd unsigned char from the beginning of u.

    Are you starting to see it?

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

Sidebar

Related Questions

I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
I have the following code: int main(int argc, char** argv) { onelog a; std::cout
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
Say we have the following code: int main(){ int a[3]={1,2,3}; printf( E: 0x%x\n, a);
Suppose you have the following code: int main(int argc, char** argv) { Foo f;
I have following code: #include <cstring> #include <boost/functional/hash.hpp> #include <iostream> int main(int argc, char
I have the following code: int main() { // Variables char name; // Take
When I execute the following code: int main() { char **temp; printf(Size of **temp
I have the following code int main() { int a=6; void *p; p=&a; p++;
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =

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.