malloc(10 * sizeof *pointer); Use The operator sizeof produces the required memory storage space of its operand when the code is compiled. The operand is written following the keyword sizeof and may be the symbol of a storage space, e.g., a variable, an expression, or a type cast. The latter is a type name enclosed in parentheses. The result of the operator is the size of the operand in bytes, or the size of the memory storage requirement. For expressions, it evaluates to the representation size for the type that would result from evaluation of the expression, which is not performed. For example, since sizeof (char) is defined to be 1 and assuming the integer type is four bytes long, the following code fragment prints : char c; printf ("%zu,%zu\n", sizeof c, sizeof (int)); Certain standard header files, such as stddef.h, define size_t to denote the unsigned integral type of the result of a sizeof expression. The printf width specifier z is intended to format that type. sizeof cannot be used in C preprocessor expressions, such as , because it is an element of the programming language, not of the preprocessor syntax, which has no data types. The following example in C++ uses the operator sizeof with variadic templates. template <typename... Args> std::size_t GetSize (Args&&... args) { /* Get size of parameter pack.*/ std::size_t Count= sizeof... (Args); return Count; } sizeof can be used with variadic templates in C++11 and above on a parameter pack to determine the number of arguments. Application to arrays When sizeof is applied to the name of an array, the result is the number of bytes required to store the entire array. This is one of the few exceptions to the rule that the name of an array is converted to a pointer to the first element of the array, and is possible just because the actual array size is fixed and known at compile time, when the sizeof operator is evaluated. The following program uses sizeof to determine the size of a declared array, avoiding a buffer overflow when copying characters: #include <stdio.h> int main(int argc, char **argv) { char buffer[10]; /* Array of 10 chars */ /* Copy at most 9 characters from argv[1] into buffer, * null-terminate the buffer. */ snprintf(buffer, sizeof buffer, "%s", argv[1]); return 0; } Here, is equivalent to , which evaluates to 10, because the size of the