include<iostream.h>
void main()
{
int i=o;
i=400*400/400;
cout<<i;
}
i am getting a wrong output
What output are you expecting? What are you getting? What is your thoughts on why they may not be the same?
i am getting a wrong output
This sentence tells us nothing, tell us WHAT output you have and how it is different from what you expected. THAT would provide us possibly more info to help solve your question.
The multiply and divide operators are of equal precidence for C/C++ compilers. What order they are evaluated it is up to the compiler. IE, your 400*400/400
expression can be evaluated as 400*(400/400) == 400
, or (400*400)/400 == 400
. Gee, they compute the same. If you aren't getting 400 as a result, then something else is going on!
int i=o;
That's not a number. It's the letter 'o'.
I'm not so proficient in C and C++, but I guess such things as assigning a char to an int are still possible?
@ddanbe: A char is an integer type so it can be implicitly converted to an int. Since sizeof(char) <= sizeof(int)
there is no loss of precision. C++ uses 5.2.4.2.1 from the C standard for its integer sizes. http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf Page 22.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.