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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:20:51+00:00 2026-05-31T20:20:51+00:00

Can I declare an int array, then initialize it with chars? I’m trying to

  • 0

Can I declare an int array, then initialize it with chars? I’m trying to print out the state of a game after each move, therefore initially the array will be full of chars, then each move an entry will be updated to an int.

I think the answer is yes, this is permitted and will work because an int is 32 bits and a char is 8 bits. I suppose that each of the chars will be offset by 24 bits in memory from each other, since the address of the n+1’th position in the array will be n+32 bits and a char will only make use of the first 8.

It’s not a homework question, just something that came up while I was working on homework. Maybe I’m completely wrong and it won’t even compile the way I’ve set everything up?

EDIT: I don’t have to represent them in a single array, as per the title of this post. I just couldn’t think of an easier way to do it.

  • 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-31T20:20:53+00:00Added an answer on May 31, 2026 at 8:20 pm

    You can also make an array of unions, where each element is a union of either char or int. That way you can avoid having to do some type-casting to treat one as the other and you don’t need to worry about the sizes of things.

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

Sidebar

Related Questions

I need to declare 3d array variable but can't. int[][][] ary = new int[5][2][];
I can: declare @idOrder int set @idOrder = 21319 I want: declare @idOrder int
can we declare a function in a header file in following way? extern int
How to initialize a 2D array with pointer. int *mapTable[] = { {1,10} ,
I can declare a structure: typedef struct { int var1; int var2; int var3;
I'm trying to read a date out of a text file then parse the
I would like to get a two dimensional int array arr that I can
In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN
Is there any way can declare a bean in just like JSP UseBean in
How i can declare a global method in delphi prism using the __Global class?

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.