Is the sizeof(some pointer) always equal to four?
For example: sizeof(char*) returns 4. As does int*, long long*, everything that I’ve tried. Are there any exceptions to this? 17 Answers 17
For example: sizeof(char*) returns 4. As does int*, long long*, everything that I’ve tried. Are there any exceptions to this? 17 Answers 17
First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf(“%u\n”, sizeof(days)); printf(“%u\n”, sizeof(ptr)); return 0; } Is there a way to find out the size of the array that ptr is pointing to (instead of just giving its size, which is four bytes on a 32-bit system)? … Read more
I want to know the size occupied by a JavaScript object. Take the following function: function Marks(){ this.maxMarks = 100; } function Student(){ this.firstName = “firstName”; this.lastName = “lastName”; this.marks = new Marks(); } Now I instantiate the student: var stud = new Student(); so that I can do stuff like stud.firstName = “new Firstname”; … Read more
Here is the code compiled in dev c++ windows: #include <stdio.h> int main() { int x = 5; printf(“%d and “, sizeof(x++)); // note 1 printf(“%d\n”, x); // note 2 return 0; } I expect x to be 6 after executing note 1. However, the output is: 4 and 5 Can anyone explain why x … Read more
Why does the sizeof operator return a size larger for a structure than the total sizes of the structure’s members? 12 s 12 This is because of padding added to satisfy alignment constraints. Data structure alignment impacts both performance and correctness of programs: Mis-aligned access might be a hard error (often SIGBUS). Mis-aligned access might … Read more
I want to know how to get size of objects like a string, integer, etc. in Python. Related question: How many bytes per element are there in a Python list (tuple)? I am using an XML file which contains size fields that specify the size of value. I must parse this XML and do my … Read more