diff options
author | Oskar <[email protected]> | 2024-08-21 20:55:10 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-21 20:55:10 +0200 |
commit | 4c8377e5711e2c864c8754d1d6373c09da2ce7e1 (patch) | |
tree | d3c8703a39cb8bd2f1a3b22c868141f8eba35e95 /sizeof-tests.cpp | |
parent | e747f69eb9b34f2c99472ca1cd17e049c1b74c9c (diff) |
more exercises
Diffstat (limited to 'sizeof-tests.cpp')
-rw-r--r-- | sizeof-tests.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sizeof-tests.cpp b/sizeof-tests.cpp new file mode 100644 index 0000000..96a8323 --- /dev/null +++ b/sizeof-tests.cpp @@ -0,0 +1,59 @@ +#include <iostream> +#include <vector> + +/* + * + * + * + * + */ + +int main () { + + std::vector<int> iv1; + std::vector<int> iv2 = {1,2,3,4,5,6,7,8,9,10}; + std::vector<std::string> sv1; + std::vector<std::string> sv2; + std::string ss0; + std::string ss1 = "Hello, World!"; + std::string ss2 = "Hello, World!"; + std::string ss3 = "Hello, World!"; + std::string ss4 = "Hello, World!"; + std::string ss5 = "Hello, World!"; + sv2.push_back(ss1); + sv2.push_back(ss2); + sv2.push_back(ss3); + sv2.push_back(ss4); + sv2.push_back(ss5); + char *p = nullptr; + char aa[10]; + std::cout << "ss0 " << sizeof(ss0) << std::endl; + std::cout << "ss1 " << sizeof(ss1) << std::endl; + std::cout << "sv1 " << sizeof(sv1) << std::endl; + std::cout << "sv2 " << sizeof(sv2[0]) << std::endl; + std::cout << "iv1 " << sizeof(iv1) << std::endl; + std::cout << "iv2[0] " << sizeof(iv2[0]) << std::endl; + std::cout << "char " << sizeof(char) << std::endl; + std::cout << "int " << sizeof(int) << std::endl; + std::cout << "int32_t " << sizeof(int32_t) << std::endl; + std::cout << "long " << sizeof(long) << std::endl; + std::cout << "long long " << sizeof(long long) << std::endl; + std::cout << "int64_t " << sizeof(int64_t) << std::endl; + std::cout << "uint64_t " << sizeof(uint64_t) << std::endl; + std::cout << "*aa " << sizeof(*aa) << std::endl; + std::cout << "aa " << sizeof(aa) << std::endl; + std::cout << "*p " << sizeof(*p) << std::endl; + std::cout << "p " << sizeof(p) << std::endl; + int iii[100]; + int *ip = iii; + std::cout << "iii " << sizeof(iii) << std::endl; + std::cout << "ip " << sizeof(ip) << std::endl; + std::cout << "*ip " << sizeof(*ip) << std::endl; + std::cout << "iii[0] " << sizeof(iii[0]) << std::endl; + std::cout << "&iii " << &iii << std::endl; + std::cout << "&iii[0] " << &iii[0] << std::endl; + std::cout << "ip " << ip << std::endl; + std::cout << "&(*ip) " << &(*ip) << std::endl; + std::cout << "&ip[0] " << &ip[0] << std::endl; + return 0; +} |