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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:06:23+00:00 2026-05-18T21:06:23+00:00

I have two questions. 1) What does a constructor really do? What happens if

  • 0

I have two questions.

1) What does a constructor really do? What happens if we don’t use constructors while declaring an instance?

2) Can you tell me the difference between these two?

A a(1,2)

A *a = new A(1,2)

Best regards.

  • 1 1 Answer
  • 1 View
  • 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-18T21:06:24+00:00Added an answer on May 18, 2026 at 9:06 pm

    A constructor initializes the member variables of the class so that it is ready for use. The result of not using a constructor when declaring an instance varies on context.

    If you are allocating a variable on the heap, like so:

    A *a;
    

    a will point to a random address in memory until it is assigned to NULL or 0, or an existing or new instance of a class, e.g.:

    A *a = new A(1, 2);
    

    If you are allocating a variable on the stack, the following syntax is used:

    A a(1, 2); // if parameters are used
    A a; // if no parameters are used
    

    Both of the above call the constructor of class A, allocating an instance of it on the stack. So, that answers both your questions – your first example allocates an instance of A on the stack, and the second allocates an instance of A on the heap.

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

Sidebar

Related Questions

I have two questions. Does it make sense when I have to choice of
I have two questions here. How can I show the header of the pop
I have two questions. How can I get the spinner in the figure below
I have two questions. Question1: How can we add a reference to a third-party
I have two questions about the following code. 1. How to constructor the third
I have two questions. I know it is possible to declare class objects in
I have two questions. I want to send SMSes from a web-site in PHP
I have two questions in regards to the PyDev (Python editor for Eclipse) and
I have two questions: 1) I have a few global variables for my website
I have two questions: (1) I learned somewhere that -O3 is not recommended with

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.