Curiosity to learn? Well, obviously not just that but because I actually want to know how operators are actually used. sizeof() seemed to be an interesting choice to me. Also, I started looking at more and more of assembly code recently and when I saw what happens at sizeof, it was just a movl which basically just moves the value into a register (the 'esl' one, or so, I guess? But I don't remember that so I'll need to take another look). This led me to thinking that the sizes of int, float, etc are pre-stored but that can't be true because let's say you put in a string, there must be an algorithm through which it calculates the size rather than just doing something along these lines (which was my first thought)
Code:
while ( *(str++) != '\0' )
{
size++;
}
return size;
//time complexity would increase if string was long and also I read somewhere that sizeof() is performed in compile-time or something like that
//so if I enter a string in run time and then have a statement somewhere later in the program saying sizeof(str), how would it be determining it
//Gradually, I was derailed off my original lines of thought which brought me here to ask the question
So, why and how exactly does it work would be my question in short?