How will you find the size of a structure in C/C++ language without using sizeof operator. (Note: sum of sizes of all fields of a structure may not be equal to the exact memory allocated to the structure. See, Method-1 in solution).
sizeof operator returns size in bytes. For example, In an implementation where 2 bytes (16bits) of memory is allocated to an int type, the below code will output 2 int x = 10; printf(“%d”, sizeof(x)); // Output amount of memory allocated to int data type. We talked about the sizeof operator in great detail in the last post. If we […]
sizeof is a unique operator in C/C++ language which returns the amount of memory (in bytes) allocated to its operand. For example, if an implementation stores an integer in 2 bytes then both the statements below will output 2. printf(“%d”, sizeof(int)); int x = 10; printf(“%d”, sizeof x); Note than sizeof operator is used like a […]