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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:44:44+00:00 2026-06-18T05:44:44+00:00

Consider this code: #include <iostream> using namespace std; void Func(int&& i) { ++i; }

  • 0

Consider this code:

#include <iostream>
using namespace std;

void Func(int&& i) {
    ++i;
}

int main() {
    int num = 1234;
    cout << "Before: " << num << endl;
    Func(std::move(num));
    cout << "After: " << num << endl;
}

Its output is:

Before: 1234
After: 1235

Clearly, i is being modified inside Func, as it is bound to parameter i after being “converted” to an r-value reference by std::move.

Well, my point:

Moving an object means transferring ownership of resources from one object into another. However, built-in types holds no resources because they themselves are the resources. It makes no sense to transfer the resources they hold. As shown by the example, num‘s value is modified. Its resource, its self, is the one being modified.

Do built-in types have move semantics?

Also, Do built-in type objects after it is moved (if it is) a well-defined behavior?

  • 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-18T05:44:45+00:00Added an answer on June 18, 2026 at 5:44 am

    And so, is the one shown by the example a well-defined behavior?

    Yes, the behaviour shown in the example is the only behaviour allowed by the standard. That is because std::move doesn’t move. The things that move are move constructors and move assignment operators.

    All std::move does is change an lvalue into an xvalue, so that it can bind to rvalue references. It does not invoke any constructor or anything else. Changing the value category happens at the type level. Nothing happens at runtime.

    Rvalue references are still references: they refer to the original object. The function increments the original integer through the reference given.

    If a function takes an argument by reference, no copies nor moves happen: the original object is bound to the reference.

    If a function takes an argument by value, then we might have a move.

    However, fundamental types don’t have move constructors. Moves degrade to copies in that case.

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

Sidebar

Related Questions

Consider this code: #include <iostream> #include <type_traits> using namespace std; template<typename T_orig> void f(T_orig&
Consider this code: #include <iostream> using namespace std; int main() { bool lock =
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
Consider this code: #include <iostream> void f(int&& i) { std::cout << f(int&&)\n; } void
Consider this: #include <iostream> using namespace std; class A{ protected: void some_function(int params) {
Consider this C++ code: #include <iostream> using namespace std; struct B { virtual int
Consider this code: #include <iostream> using namespace std; typedef int array[12]; array sample; array
Consider the below code: #include <iostream> using namespace std; int main () { int
Consider this code #include <iostream> #include <cstdio> using namespace std; class Dummy { public:
Consider this code : #include <iostream> #include <typeinfo> using namespace std; template<typename T1, typename

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.