Hi all, as you can see I am a newbie to this forum and would like to start by asking a question that was asked to me in my recent interview.
1.) How would you find whether a variable is overflowing in C using normal C syntax and features?. For example lets assume there is a int variable and you try to store a long in that, obviously the compiler would not give a compile time error. It will give an output at the cost of sacrificing an overflow. Is there any way to find a variable overflow that you can code inside your program to spit out a user defined error using a printf statement if that happens?.
2.) How would you store a float number like -12.12345 in a signed long without losing precision? Is this possible because the bit width of the number above is waay less than what can be stored in a signed long or is it impossible to store precision in a signed long?
Thanks and waiting for your replies guys!!. sorry if I have phrased the question in a way you cant understand. I promise i`ll improve ..
1.) How would you find whether a variable is overflowing in C using normal C syntax and features?. For example lets assume there is a int variable and you try to store a long in that, obviously the compiler would not give a compile time error. It will give an output at the cost of sacrificing an overflow. Is there any way to find a variable overflow that you can code inside your program to spit out a user defined error using a printf statement if that happens?.
2.) How would you store a float number like -12.12345 in a signed long without losing precision? Is this possible because the bit width of the number above is waay less than what can be stored in a signed long or is it impossible to store precision in a signed long?
Thanks and waiting for your replies guys!!. sorry if I have phrased the question in a way you cant understand. I promise i`ll improve ..