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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:38:55+00:00 2026-06-12T02:38:55+00:00

I have something like this: int* a = NULL; int* b = *a; b

  • 0

I have something like this:

int* a = NULL;
int* b = *a;

b = new int(5);
std::cout << *a;
std::cout << *b;

I would like to instantiate a from b so a has the value 5. Is this possible?

EDIT:

actual code is something like this –

int* a = null; //Global variable
int* b = null; //Global variable

int* returnInt(int position)
{
    switch(position)
    {
      case 0:
         return a;
      case 1:
         return b;
     }
}

some other function -

int* c = returnInt(0); // Get Global a

if (c == null)
    c = new int(5);

i want to instantiate the global variables this way if possible.

  • 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-12T02:38:57+00:00Added an answer on June 12, 2026 at 2:38 am
    int* a = NULL;
    int* b = *a; //here you dereference a NULL pointer, undefined behavior.
    

    You need

    int* b = new int(5);
    int*& a = b; //a is a reference to pointer to int, it is a synonym of b
    std::cout << *a;
    std::cout << *b;
    

    Or, a could be a reference to int and be a synonym for *b

    int* b = new int(5);
    int& a = *b; //a is a reference to int, it is a synonym of `*b`
    std::cout << a;  //prints 5
    std::cout << *b; //prints 5
    a = 4;
    std::cout << a;  //prints 4
    std::cout << *b; //prints 4
    

    Please consult a good C++ book for details.

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

Sidebar

Related Questions

I have something like this: #include <iostream> #include <map> int main() { std::map<int, int*>
I have something like this: create table account ( id int identity(1,1) primary key,
Suppose I have something like this: class A { public B mem; public int
Okay, I have something like this in C++: class MyClass{ private: int someVariable; int
I have a constexpr function that looks something like this: constexpr int foo(int bar)
I have two tables which looks something like this Table Queue int ID; string
I have class Employee which is something like this. class Emp { int EmpID;
I have something like this: [{'date': 1, 'value':5}, {'date':2,'value':3}, ...] and want to map
I have something like this: class SomeClass { public int Id {get;set} public int
I have something like this: #define QUIT_TIME 5 int main(int argc, char **argv) {

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.