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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:40:03+00:00 2026-05-23T02:40:03+00:00

When writing C++, let’s assume the following line of code: Object* obj = new

  • 0

When writing C++, let’s assume the following line of code:

Object* obj = new Object(); 

If this line both compiles and does not cause exceptions or any other visible
runtime problems, can obj be NULL right after this line was executed?

  • 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-23T02:40:04+00:00Added an answer on May 23, 2026 at 2:40 am

    No, obj cannot be NULL.

    If new fails, it will throw a std::bad_alloc exception. If no exception was thrown, obj is guaranteed to point to a fully initialized instance of Object.

    There is a variant of new that doesn’t throw an exception

    Object *obj = new(nothrow) Object();
    

    In this case, obj will be NULL if new fails, and the std::bad_alloc exception will not be thrown (though Object‘s constructor can obviously still throw exceptions).

    On some older compilers, new might not throw an exception and rather return NULL instead, but this is not standards-compliant behaviour.

    If you’ve overloaded operator new, it might behave differently depending on your implementation.

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

Sidebar

Related Questions

Let's face it: writing proper, standards compliant HTML is quite difficult to do. Writing
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say that I'm writing a function to convert between temperature scales. I want
Let's say that I'm writing a library in C# and I don't know who
I've been writing a little application that will let people upload & download files
Is it possible to wipe strings in Delphi? Let me explain: I am writing
Writing the code for the user authentication portion of a web site (including account
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
Let's say I'm writing an application and I need to be able to do

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.