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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:31:48+00:00 2026-05-16T17:31:48+00:00

I’ve just read this that by pointing a pointer to the first array member,

  • 0

I’ve just read this that by pointing a pointer to the first array member, you can cycle through by adding to the pointer.

char my_array[] = "I am an array of chars";

char *my_pointer = my_array;

printf("%c\n", *my_pointer);

my_pointer++;

printf("%c", *my_pointer);

I guess this implies array members are always stored sequentially, and the space allocated is always reserved and an array’s size can not be extended (because after the length it may contain other things in memory)?

Why does this work exactly? When accessing an array using a subscript, like my_array[5], will C only know where the array starts (i.e. my_array[0]), and have to increase an internal pointer by 5 to return it?

I apologize if this seems obvious, but I’ve spent my life in high level languages and C is very interesting 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-16T17:31:49+00:00Added an answer on May 16, 2026 at 5:31 pm

    Putting aside the problems with your code, yes, arrays are contiguous elements.

    What happens with the second line of the code snippet below:

    int * iptr = malloc (40 * sizeof(int));
    int x = iptr[10];
    

    is thus:

    • the value 10 is multiplied by the size of the int to get 70 (in this example, we assume a 7-byte int).
    • this is then added to the base pointer iptr (unscaled) and the (7-byte) value is extracted from that location.

    This scaling is an important feature. You won’t see it when you’re working with char arrays but the values &(iptr[0]) and &(iptr[1]) will be separated by the size of an int, not a char (7 in our example case above).

    When you add 1 to a pointer, that doesn’t actually add 1, it adds the size of the underlying data type. So that:

    int *p = &(iptr[0]);
    p++;
    

    won’t give you an address corresponding to the second byte of that memory, it will actually give you the address of the second int (the seventh byte).

    To that end, iptr[3] is exactly equivalent to *(i+3) in that they both give you element number three, even though it’s made up of bytes from offset 21 through 27 inclusive.


    Pre-emptive strike, just in case: keep in mind that a byte in ISO C is not necessarily 8 bits. ISO uses the term octet for that. A byte is the size of a char.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

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.