2

Why isnt sizeof(a()); isn't printing helo ? Why the Function is not called.

But cbrt is also a function and it is calling a(); and printing helo clearly.

But why isn't sizeof(a()); calling a(); What is happening inside the compiler.

Why sizeof(a()); unable to call the function a();

But

cbrt(a()); is clearly able to call function a();

sizeof(a());



#include<stdio.h>
#include<math.h>
int main()
{ 
    printf("%d\n",sizeof(a()));
   
}
int a()
{
    printf("Helo");
    return 0;
}

https://i.stack.imgur.com/NBMaV.jpg

But cbrt(a());


#include<stdio.h>
#include<math.h>
int main()
{ 
    printf("%d\n",cbrt(a()));
   
}
int a()
{
    printf("Helo");
    return 0;
}


https://i.stack.imgur.com/NMp33.jpg

Aditya
  • 23
  • 4
  • Unless you're checking `sizeof` on a VLA, `sizeof`'s operand is not evaluated. – mediocrevegetable1 Jun 08 '21 at 17:37
  • 3
    `cbrt(a()); is clearly able to call function a();` No, _you're_ calling `a()` and passing the result to `cbrt`. The operand of `sizeof` is not evaluated, it doesn't need to be to know the size. – GManNickG Jun 08 '21 at 17:37
  • `sizeof` is evaluated at compile time. When do you think the function will be called? – William Pursell Jun 08 '21 at 17:40
  • 1
    `sizeof` is an operator not a function, its operand is normally evaluated at compile time not run time, and the evaluation merely determines the size of the type yielded by the expression. In this case the sizeof(int), because `int` is the _type_ of the expression `a()`. – Clifford Jun 08 '21 at 17:42
  • You can't use `%d` with the result of `sizeof`. The results may be incorrect if you do. Use `%zu` instead. – Tom Karzes Jun 08 '21 at 18:03
  • What is the data type of printf ? – Aditya Jun 08 '21 at 18:05
  • I think its taking the data type of printf which i guess is integer and that's why it's showing 4 bytes. – Aditya Jun 08 '21 at 18:05
  • @Aditya read the documentaion of printf. Everything is there – 0___________ Jun 08 '21 at 18:41

0 Answers0