fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct myobject {
  5. int x;
  6. std::string y;
  7. double z;
  8. };
  9.  
  10. int main() {
  11. // your code goes here
  12. myobject obj1 = {
  13. 42, "hello", 42.42
  14. };
  15. unsigned char* bytes1 = new unsigned char[sizeof(obj1)];
  16. memcpy(bytes1, obj1, sizeof(obj1));
  17. myobject obj2 = {
  18. 42, "hello", 42.42
  19. }
  20. unsigned char* bytes2 = new unsigned char[sizeof(obj2)];
  21. memcpy(bytes2, obj2, sizeof(obj2));
  22.  
  23. std::cout << memcmp(bytes1, bytes2, sizeof(bytes1)) << '\n';
  24.  
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:35: error: ‘memcpy’ was not declared in this scope
  memcpy(bytes1, obj1, sizeof(obj1));
                                   ^
prog.cpp:20:2: error: expected ‘,’ or ‘;’ before ‘unsigned’
  unsigned char* bytes2 = new unsigned char[sizeof(obj2)];
  ^~~~~~~~
prog.cpp:21:9: error: ‘bytes2’ was not declared in this scope
  memcpy(bytes2, obj2, sizeof(obj2));
         ^~~~~~
prog.cpp:23:52: error: ‘memcmp’ was not declared in this scope
  std::cout << memcmp(bytes1, bytes2, sizeof(bytes1)) << '\n';
                                                    ^
stdout
Standard output is empty