Hi all,

I am new to C++, I am studying a C++ code and would like to learn how to implement it in Python.

I encountered the following:
1 unsigned short arr1[2];
2 unsigned int arr2 = (unsigned int ) arr1;

I tried to write a C++ code to see the effect of the second line:

    arr2[0] = 6553621;  //some random big number 

    cout<< "arr1[0] is "  << arr1[0] <<endl;
    cout<< "arr1[1] is "  << arr1[1] <<endl;
    cout <<"arr2[0] is " <<arr2[0] <<endl;
    cout <<"arr2[1] is " <<arr2[1] <<endl;

,and I got the following:
arr1[0] is 21
arr1[1] is 100
arr2[0] is 6553621
arr2[1] is 1257984000

My question is how to get the values in arr1[0] and arr1[1] after 6553621 is assigned to arr2[0]?

Re: C++ to Python Conversion 80 80

I think you'll have to explain more about what exactly the code is supposed to do. The second line, unsigned int arr2 = (unsigned int ) arr1;, should throw a compiler error, since casting a pointer to an unsigned int can result in loss of information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.