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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:28:56+00:00 2026-05-26T22:28:56+00:00

I am an intermediate java programmer and I am used to relaying on the

  • 0

I am an intermediate java programmer and I am used to relaying on the null value in java for cheking if objets are initialized with some reference to instanced object in memory. I want to do something similar in c++ but I do not have a clear idea about how I can achieve it. I want to initialize a user array – user is a class I have defined – so I can check if the actual position in the array does contain an object or it is free.

I have tried to use the null definition in c++ but found out that it is simply a “-1” int value and I could not use it properly. So basically I need something to distinguish between a free position in my array and an ocuppied one.

Additionally I might be interested in having an extra value to distinguish a position that contained a removed user, since I am planning to just mark the desired position with a special mark as a freed position when it comes to the method that remove a user from the array.

For the curious ones, I am implementing a simple hash set and the remove method in my class just mark the position of the element to remove instead of doing some restruction.

  • 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-26T22:28:57+00:00Added an answer on May 26, 2026 at 10:28 pm

    I think there are some concept you need to understand.

    Unlike Java, when you are creating an N-element array of User, it is NOT an array of reference. It is really a piece of memory containing actual N user, which is already created and initialized (i.e. constructor already run). (Well, there are more advanced topics like placement-new but I think it is not really what you are looking for yet)

    So it is somehow contradicting if you said you have an “array of User” and want to keep track if certain position is initialized.

    Unless:

    1. You are not creating array of User, but Array of “Pointer to User” (or other reference like auto_ptr). By such way, it is meaningful to say certain element is “null”; or

    2. Your “initialize” do not mean creating an object instance, but an explicit initialization action (like executing an init() method of an User instance). By such way, it is meaningful to say certain element is “not initialized”.

    (First of all, as you are writing C++, I shall recommend you to use std::vector, not array. However I am using array in this answer, as to stick close to your question)

    For case 1, it is strict forward, simply use NULL (avoid using 0, because, although NULL is defined as 0 in most system, using NULL actually makes the code more readable and more portable):

    User* user[10] = {NULL};   // array of 10 pointer-to-User
    user[0] = new User(...);
    assert (user[0] != NULL);
    assert (user[1] == NULL);
    

    For case 2, you have many other choice, like keeping another array of boolean to keep the “initialized” flag, or have a wrapper over User for such extra flag, or simply add such flag into your User class, etc.

    e.g.

    User user[10];   // 10 element of User, which all of them is already created
    //assume you have extra flag in User
    user[0].init(...);  // explicity do some init work on user[0]
    //......
    if (! user[5].isInitialized()) {
      user[5].init(...);
    }
    

    (honestly I think case 2 is not really what you are looking for)

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

Sidebar

Related Questions

I'm a beginner to intermediate programmer and I've learned some java and C#. I
This may sound too trivial for an intermediate Java programmer. But during my process
I'm an intermediate java coder, writing a librarian Java app, and for some reason
I am an intermediate level Java programmer (with more experience in C# and PHP),
I'm an intermediate programmer. I know C very well, Java somewhat well, and have
I am an intermediate C programmer. If you have made any coding mistake that
I am a novice-intermediate programmer taking a stab at AJAX. While reading up on
I'm a novice-to-intermediate JavaScript/jQuery programmer, so concrete/executable examples would be very much appreciated. My
As a programmer used to developing native applications, I'm expanding my horizons and developing
Need some help with crypto routines in Java. Given a PKCS#7 signature, I want

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.