Anything written in sizeof() is never executed in C

CServer Side ProgrammingProgramming

The sizeof function (Sometimes called operator) is used to calculate the size of the given argument. If some other functions are given as argument, then that will not be executed in the sizeof.

In the following example we will put one printf() statement inside the loop. Then we will see the output.


double my_function() {
   printf("This is a test function");
   return 123456789;
main() {
   int x;
   x = sizeof(printf("Hello World"));
   printf("The size: %d\n", x);
   x = sizeof(my_function());
   printf("The size: %d", x);


The size: 4
The size: 8

The printf() is not executed which is present inside the sizeof(). Only the return type is considered, and its size is taken.

Published on 02-May-2019 12:26:42