--- Gopi Krishna Komanduri <[EMAIL PROTECTED]>
wrote:
> Hi ,
> I want to know 3 things.
#1 answered by Thomas.
> 2)why SIZEOF is an operator not a function? The
> syntax resembels a function but still it is an
> operator . why so? is it like , as the value of size
> needs to be known at compile time itself , thatz why
> it is a operator not a function or what?
Because the creator of C++ wanted sizeof to be an
operator.
> 3) Is there any way to find 2 power x when we are
> provide x , but that has to happen in single stmt .
> I tried with shift operators but unable to find out.
> Could you please help me out in these.
y = std::power(2,x);
> 4) main()
> {
> printf("%d");
> };
> In the above , the output I am getting is
> garbage. But what I am thinking is as printf is a
> function and %d is one parameter and no other
> parameters , it will push only %d onto stack . so
> when it starts executing , it will pop only %d and
> it won't get any other value from stack to resolve
> that %d. So May I know how compiler is giving some
> garbage , with out stops printing?
>
printf uses the first parameter to determine the other
parameters to be used. This is where the programmer
has to be smarter than the computer. It will not give
an error of the string says there are 3 values to
output and you pass 2 or 4. The error is a logic
error (checked by the programmer) not a syntax error
(checked by the compiler). When printf sees the %d
that you have passed to it, it take the location where
the next value should have been and outputs that value
as an integer. It is doing exactly what you told it
to do, output an integer. It doesn't know that you
didn't give it a valid value to output.
Ray
>
>
>
> Thanks Regaerds,
> gopi.k
____________________________________________________________________________________Ready
for the edge of your seat?
Check out tonight's top picks on Yahoo! TV.
http://tv.yahoo.com/