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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:00:31+00:00 2026-06-09T03:00:31+00:00

I have done type casting with int and char but not with pointers so

  • 0

I have done type casting with int and char but not with pointers so I posted this question.

#include <stdio.h>
int main() {
    int a[4] = { 1, 2, 6, 4 };
    char *p;
    p = (char *)a;   // what does this statement mean?
    printf("%d\n",*p);
    p = p + 1;        
    printf("%d",*p);  // after incrementing it gives 0 why?
}

The first call to printf gives the first element of the array. And after p=p+1 it gives 0. Why?

  • 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-09T03:00:33+00:00Added an answer on June 9, 2026 at 3:00 am
    int a[4] = { 1, 2, 6, 4 };
    

    declares a as array. a at this point of time stores the address of the first element of the array.

    char *p;
    

    declares p as a pointer to character

    p = (char *)a;
    

    Now since p & a both stores addresses. So the address stored at a (address of first element of the array) is assigned to p. The typecasting is done as p was declared as char *

    what it does is that, assuming address stored at a is say 100 and assuming that int takes 2 bytes and char takes 1 bytes in memory

    a+1 would return a+size of int(2) = 102
    

    and

    p+1 would return p+size of char(1) = 101 
    

    and that will explain the output as

    A. two bytes stored at a contains the first element of the array.

    B. one byte stored at p is the character representation of the first byte of integer 1, which is 0.

    Hope this helps.

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

Sidebar

Related Questions

i have done this so far: api_configs({ color:'grey', type:'fast' }); function api_configs(confs){ for(var c
I have done this a gazillion times before but my memory fails me and
I have done this many times but can't remember the syntax for the life
I have done some LINQ, it works great but I'm not a fan of
I have done jQuery and Ajax, but I am not able to get the
I want my keyboard to have caps lock on, this is done by mEditText.setInputType(TYPE_TEXT_FLAG_CAP_CHARACTERS);
I have done some looking and I found this: http://www.codeproject.com/Articles/14439/The-ScrollableListBox-Custom-Control-for-ASP-NET-2 but to me it
I'm currently writing out xml and have done the following: header (content-type: text/xml); header
I have done I custom class method for NSString to md5 a NSString. This
I ll reframe my question based on some research I have done? I need

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.