i worked on below code and have few questions:
int main()
{
//char just_c(char a);
int just_i(int a);
double just_d(double a);
//char fun(char c);
printf("char1 :%d\n",sizeof(fun('a')));
printf("char: %d\n",sizeof(just_c('a')));
printf("int : %d\n",sizeof(just(1)));// retained purposefully
// not generating any error.
printf("double : %d\n",sizeof(just(1.1)));
//printf("just :%d\n",just(1));
return 0;
}
char just_c(char c)
{
return c;
}
int just_i(int c)
{
return c;
}
double just_d(double c)
{
return c;
}
char fun(char c)
{
return c;
}
in the program above
(i) when you call a function using sizeof ( just_c('a'));
the out put is 1, when i have the prototype of the function
4 if i dont have the prototype of the function .
the statement
printf("char: %d\n",sizeof(just_c('a')));
produces 4 without proto, and 1 with proto, why is it so?
is it making use of return type of the function?
2.sizeof is compile time operator. what does that mean ?It means that sizeof(expr) will probably be processed by the compiler and replaced with a constant value before generating object code. For example, if the size of an int is 4 on a hypothetical machine, the compiler might process printf("%lu\n", (unsigned long)sizeof(int)); and replace it with printf("%lu\n", (unsigned long)4UL); .
this is fine as long as i use only objects and types.
But,
if i write any functions in sizeof operator its not generating any errors rather its giving different outputs as mentioned above ( i )
ii) i …