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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:45:26+00:00 2026-05-29T07:45:26+00:00

I was refreshing my understanding of value-initialisation versus default-initialisation, and came across this :

  • 0

I was refreshing my understanding of value-initialisation versus default-initialisation, and came across this:

struct C {
    int x;
    int y;
    C () { }
};

int main () {
    C c = C ();
}

Apparently this is UB because

In the case of C(), there is a constructor that is capable of
initializing the x and y members, so no initialization takes place.
Attempting to copy C() to c therefore results in undefined behavior.

I think I understand why, but I’m not certain. Can someone please elaborate?

Does that mean this is also UB?

int x; x = x;

Incidentally, with regards to value initialisation, is the following guaranteed to be zero?

int x = int ();
  • 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-29T07:45:27+00:00Added an answer on May 29, 2026 at 7:45 am

    Your first example has undefined behavior because the default, compiler
    generated copy constructor will do a memberwise copy, ints may have
    trapping values, and reading a trapping value to copy it may cause the
    program to crash.

    In practice, I can’t imagine this ever actually crashing; the compiler
    will almost certainly optimize the copy out, and even if it didn’t, it
    would likely use some special bitwise copy which would copy without
    checking for trapping values. (In C++, you are guaranteed to be able to
    copy bytes.)

    For the second case, again, undefined behavior. Although in this case,
    you have assignment rather than copy construction, and the compiler is
    less likely to optimize it away. (There is no assignment in your first
    example, only copy construction.)

    For the third, yes. An initializer with an empty parenthese (and no
    user defined default initializer to override it) first performs zero
    initialization (exactly as occurs for variables with static lifetime).

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

Sidebar

Related Questions

Refreshing on floating points (also PDF ), IEEE-754 and taking part in this discussion
I am refreshing openmp a bit, and got into this weird situation. Shaved off
I have the following refreshing timer: <s:url id=getDeployQueue action=deploymentQueue > <s:param name=readonly value=readonly />
I am refreshing my page using jQuery: location.reload(); This is working great but I
I want to upload an image without refreshing page. please help me for this
I am trying to submit this form without refreshing the page. I'm using jquery;
I have the problem in refreshing the table. I create the table like this
I'm having problems refreshing .Net 2.0 with IIS 6. I have been able to
How exactly do you make an auto-refreshing div with JavaScript (specifically, jQuery)? I know
I understand the reason behind not auto refreshing your .dbml (Linq2Sql), .edmx (Linq2Entities) or

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.