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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:48:50+00:00 2026-05-27T06:48:50+00:00

I created a code below, where I need to keep track of an array,

  • 0

I created a code below, where I need to keep track of an array, increase the pointer to array, and stop if the array ends.

I tested using the code below and apparently after 1000 iterations of increasing ptr and printing *ptr, I get 0 as a value.

So is it true the last element of array will ALWAYS be 0? How can I tell the ptr to stop at the last element, if the array length is created dynamicaly (and I am not allowed to use linked list instead)? I am afraid that if I use below code, one day I will meet printf i=1000 , and it returns me random memory location (sofar for the code below, it is not true, but who knows)..

#include <stdio.h>

int my_array[] = {1,23,17,4,-5,100};
int *ptr;

int main(void)
{
    int i;
    ptr = &my_array[0];     /* point our pointer to the first
                                      element of the array */
    printf("value of ptr is %d\n", *ptr);
    for(i=0; i<1000; i++){
        ptr++;
    }
    printf("value of ptr is now %d", *ptr);

    return 0;
}
  • 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-27T06:48:50+00:00Added an answer on May 27, 2026 at 6:48 am

    So is this true the last element of array will ALWAYS be “0”?

    No, this is just pure luck. You are reading from a random location in your memory, you could even end up in a segmentation fault, killing your program.

    You should always make sure to not read/write over the boundaries of your array, or really bad things might happen (Segmentation faults may be the least bad one).

    You can keep track of the number of items in your array by using: sizeof(my_array)/sizeof(int)

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

Sidebar

Related Questions

I need helps on the PhP array method deployed below: Actual PhP code: $itemsB
In my code I have 2 ComboBox DropDownLists, created by the code below. The
I created a DatePicker user control (ASP code below, no code behind) which is
How to drag and drop the dynamically created controls my code is shown below
I have a dialog box, created with the code javascript and HTML generated below.
I am using below code to create a reminder in Google calendar (using Google
I'm trying to create a custom drop down and using the code below it
I am using jquery to create a custom dropdown with the code below. I
I need to replace a substring from some string. I've already created corrected code
Here in the below code i need some info on cloning there is 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.