Keanu Reaves wrote:
> hi shweta i'm frm india...The Question You Asked Has No Difference
you mean the results of the program will be the same.
> you can use one of them..but the thing is that it may give you unconditional
> results.if u r on orkut then gimme id.ok.!
>
> Thomas Hruska <[EMAIL PROTECTED]> wrote: Mickey Mathieson wrote:
>
>> --- shvetakapoor2002_cplusplus
>> <[EMAIL PROTECTED]> wrote:
>>
>>
>>> Hi All,
>>>
>>> Please help me in understanding what's the
>>> difference between the two
>>> statements below
>>>
>>> [1] cout << "Number: " << static_cast<int>(3.14159)
>>> << "\n";
>>>
>>> [2] cout << "Number: " << (int)3.14159 << "\n";
>>>
>>> Basically I want to know the difference in using
>>> static_cast<int> and
>>> using (int)
>>>
>>> Thanks,
>>> Shveta
>>>
>>>
>>>
>> http://www.cprogramming.com/reference/typecasting/staticcast.html
>>
>>
>> Mickey M.
>> Construction Partner Inc.
>> http://www.constructionpartner.com
>>
>
> Um...
>
> double result = static_cast<double>(4)/5;
>
> Pretty sure that won't work
of course it will
> and should be:
>
> double result = static_cast<double>(4)/static_cast<double>(5);
>
waste of effort.
> Or you could just skip the casting and just use doubles to begin with:
>
> double result = 4.0 / 5.0;
>
why don't you try double result = 4.0/5;
tell us all what happens
> Frankly, I've not seen much of a difference between the two types of
> casts and personally prefer the old C-style casts because it requires
> pressing fewer keys.
bad idea. Read Meyers on the topic
> However, I'll use static_cast<>() when typecasting
> a (void *) to some other type - usually the (void *) is a pointer to a
> class that is being sent to a static private callback function within
> the class itself. But for a simple "I need to convert from one basic
> type to another basic type", static_cast seems overkill.
>
it also tells the reader exactly what you mean
> IMO, cprogramming.com is a pretty unreliable site for answering C/C++
> questions. The C++ FAQ that gets referenced here often is significantly
> more accurate.
>
>