Skip to content

Files

Latest commit

 

History

History
19 lines (12 loc) · 521 Bytes

sizeofwithsilentarraypointer.md

File metadata and controls

19 lines (12 loc) · 521 Bytes

Pattern: Possible misuse of sizeof

Issue: -

Description

Using sizeof for array given as function argument returns the size of a pointer. It does not return the size of the whole array in bytes as might be expected. For example, this code:

int f(char a[100]) {
	return sizeof(a);
}

returns 4 (in 32-bit systems) or 8 (in 64-bit systems) instead of 100 (the size of the array in bytes).

Further Reading