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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:01:37+00:00 2026-06-08T15:01:37+00:00

Is it okay to use characters as array subscripts? My array is initialized to

  • 0

Is it okay to use characters as array subscripts?

My array is initialized to hold 256 objects, so it seems as though accessing out of bounds would not be an issue. But, I was getting some weird segmentation faults, which I found out were due to the fact that the character value that I was reading in was negative in some cases.

I don’t know how that is possible, however. Then, I casted it to an unsigned char, but that didn’t work either. I ended up getting boundary issues there as well. I also tried casting the char variables to ints and then accessing the array, but I still had segmentation issues.

What can I do to mitigate this? Being able to access the array via characters is nice because my program has an array cell for each character in the ASCII set. It seems to make sense, but I don’t know why its not working.

  • 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-08T15:01:38+00:00Added an answer on June 8, 2026 at 3:01 pm

    It’s perfectly valid to use values of character type as array indices. An array index can be of any integer type; char, unsigned char, and signed char are all integer types.

    But plain char can be either signed or unsigned, depending on the implementation. Either it has the same range as signed char, or it has the same range as unsigned char; either way, it’s still a distinct type.

    So if you have an array with 256 elements, you can safely index it with unsigned char, which has a range of at least 0 to 255. You can’t safely index it with char, since it could have negative values.

    Then, I casted it to an unsigned char, but that didn’t work either. I ended up getting boundary issues there as well.

    I can’t help with that without more information.

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

Sidebar

Related Questions

Is it okay to use array without single or double quotion like $array[key]? I
Possible Duplicate: Is it okay to use array[key] in PHP? Is there any significant
This might be a n00bish question, but whatever. Is okay to use exceptions for
I just want to ask if is it okay that I use native PHP
OKay I don't use actionscript and trying to help my friend edit a flash
Okay, I currently use an eggdrop IRC bot on my server. I want to
Okay so, I have to use an interface in a code I'm making involving
Okay so what i am trying to achieve is use the youtube api to
Okay, so here's my problem: We use FOP for creating pretty report output. We
Okay, here's what I'm trying to do: I'm trying to use PHP to develop

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.