fivec 31 Newbie Poster

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 …

fivec 31 Newbie Poster

Hello friends and gurus,
this is my first post here.
i have few basic C questions.
is sizeof an opearator(i actually studied it as a operator but then not so serious about the things)
1.why is it called as an opeartor?
2.sizeof is compile time operator. what does that mean ?
3.what about all other opearators arent they compile time?

its syntax and the usage is exactly like the function usage

examples:

int x;
       x=sizeof(x);
       FILE *fp;
       printf("%d",sizeof (fgetc(fp));

and sometimes i observed

sizeof(i)
    sizeof i

when can i ignore the paranthesis around the argument.

as this is my first post here, Xcuse me if i missfollow any of the forum rules. ( **though i had a glance at the rules**)

thanks .

Ancient Dragon commented: Thanks for reading the rules and using code tags. :) +24
ankur_ commented: go +1
kvprajapati commented: N/A +6