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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:34:35+00:00 2026-06-06T07:34:35+00:00

Please see the code snippet below : #include <iostream> using namespace std; int main()

  • 0

Please see the code snippet below :

#include <iostream>
using namespace std;

int main()
{
uint32_t len, x;
char abc[] = "12345678";
uint8_t *ptr = (uint8_t *)abc;
copy(ptr, ptr + 4, reinterpret_cast<uint32_t*>(&len));
cout << " len: " << len << endl;
} 

The output is 49! I would want the output to be 1234. Am I missing something

  • 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-06T07:34:37+00:00Added an answer on June 6, 2026 at 7:34 am

    Your target is a “container” of length 1 (namely, a single object, len).

    You are copying four subsequent byte values into this container, which of course fails – in particular, it causes an overflow since the target only has space for a single element.

    Other errors in your code (not an exhaustive list):

    • You are confusing character codes and their string representation
    • You are performing redundant casts

    The first point in particular is relevant since what you actually want to do is parse the number encoded in the first four characters of the string as a decimal number. But what you actually do is copy its character codes.

    To parse a number in C++, use as std::stringstream or, since C++11, std::stoi

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

Sidebar

Related Questions

Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',
I am using vb.net code. I have grid view, please see the code below:
Please see the snippet below. I am using it in a way to restrict
I have a DataGridView inside a ContextMenu control, please see the code snippet below:
I've a problem with CakePHP __() function. Please see the code below : $options
I have a grid view control in my application. Please see the below code.
i have a javascript module name SceneModule, see the code snippet below var SceneModule
I'm trying to create a dynamic ItemizedOverylay (please see the code below) on Google

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.