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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:34:05+00:00 2026-05-31T16:34:05+00:00

I need help with my C code. I have a function that sets a

  • 0

I need help with my C code. I have a function that sets a value to the spot in memory
to the value that you have input to the function.

The issue that I am facing is if the pointer moves past the allocated amount of memory
It should throw an error. I am not sure how to check for this issue.

 unsignded char the_pool = malloc(1000);
 char *num = a pointer to the start of the_pool up to ten spots
 num[i] =  val;
num[11] = val; //This should throw an error in my function which 

So how can I check to see that I have moved into unauthorized memory space.

  • 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-31T16:34:07+00:00Added an answer on May 31, 2026 at 4:34 pm

    C will not catch this error for you. You must do it yourself.

    For example, you could safely wrap access to your array in a function:

    typedef struct
    {
       char *data; 
       int length;
    } myArrayType;
    
    void MakeArray( myArrayType *p, int length )
    {
       p->data = (char *)malloc(length);
       p->length = length;
    }
    
    int WriteToArrayWithBoundsChecking( myArrayType *p, int index, char value ) 
    {
       if ( index >= 0 && index < p->length ) 
       { 
          p->data[index] = value;
          return 1; // return "success"
       }
       else 
       {
          return 0; // return "failure"
       }
    }
    

    Then you can look at the return value of WriteToArrayWithBoundsChecking() to see if your write succeeded or not.

    Of course you must remember to clean up the memory pointed at by myArrayType->data when you are done. Otherwise you will cause a leak.

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

Sidebar

Related Questions

I have a function that need to sum up from each input but at
i have this code, and need help with the logic end. I would like
I'm not good at t-sql, so I need help. I have this code I
I need syntax help with the following code logic: I have a code block
I need your help. Say I have a code inside a for statement similar
I have several questions I need help with. I'll add both my code and
I have a likely simple problem that I need help with. I have two
I need help to clear my concepts. I have a function which toggle the
I have a function that accepts an Enumerable. I need to ensure that the
I need help with changing a function that is called once the page loads,

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.