New course! Every coder should learn Generative AI!
Try a free lesson+ 1
What return type do sizeof() have?
#include <stdio.h> int main() { printf("float: %ld \n", sizeof(float)); printf("double: %lu \n", sizeof(double)); printf("char: %ld \n", sizeof(char)); return 0; } //why is sizeof return type working with both %lu and %ld format specifier
1 Answer
+ 3
Naively speaking, it is illogical to try to represent size measurement by using negative number. So size measurement fits the characteristics of unsigned integer family.
You *probably* may find incorrect or unexpected result when using signed integer %ld specifier when the size of the object to analyse (by sizeof) surpass the maximum value of signed integer data range.