+ 2
When do you use sizeof ?
i know what sizeof is doing, but i cant understand why someone would ever need a variable type in bytes.
6 Réponses
+ 3
well I mostly use sizeof to find array length 😐
+ 1
I don't know about C++, so I'll answer on what that is in C.
sizeof returns the size in bytes of an object. If you need to allocate space in memory for something, you just go
malloc(sizeof(x))
this says "allocate in memory a portion of space that is equal to the portion of space needed to allocate x"
for instance, sizeof(char c) returns 1, because you take 1 byte to store a char to memory.
sizeof(int x) returns 4, because you'll need 4 bytes to store an integer
+ 1
you said what is sizeof xD
but i mean when do you use it ? ( mind to give an example code ? (hard to me to understand without))
+ 1
For what I can recall of C, you use it a lot when working with pointers
it's been a year since I last wrote something in C, so I could really give you a wrong code and that would be more harmful that anything
+ 1
* Java array.length intensifies *
+ 1
@very_hard ik that :)
is there any other use for it ?