II-18 Programming Concepts
int main()
{
printf("Demo of return keyword");
return 0; /* '0' implies successful execution of program*/
}
16. What is the difference between %f and %g control strings? Whether both can be used for
representing float numbers?
Ans: The format string %f or %g is used to represent floating point number or real number in the form
of fraction, i.e., decimal notation. Precise results are obtained by %f. The precision indicates the number of
significant digits. In case precision is missing, i.e. for zero precision, fractional part appears with six digits.
With %g the real number or floating point number appears up to two decimal digits after decimal
point. Depending upon the applications we, therefore, can use one of them to represent the floats.
17. What do you mean by type conversion? Why is it necessary?
Ans: Type conversion converts one type of data into another type.
1. Assigning incompatible data types.
Example:
int x = 3.5;
Here, the fraction part will not be assigned to integer variable and the part will be lost. The integer
is 2-byte length data type without fractional part and float is 4-byte length data type with frac-
tional part. We can use 'float' instead.
2. Assigning out of range value.
For example, suppose that you assign 35425 to int x; you will not get expected result, because
35425 is larger than short integer range.
We may use ‘long’ instead.
3. Sometimes a programmer needs the result in a certain data type; for example, division of 5 with
2 should return float value. Practically, the compiler always returns integer values because
both the arguments are of integer data type.
To correct it, we use ( float)5/2 in the program.
18. What is wrapping around?
Ans: When the value of variable goes beyond its limit, the compiler would not flag any error mes-
sage. It just wraps around the value of a variable. For example, the range of unsigned integer is 0 to
65535. In this type, negative values and values greater than 65535 are compatible.
unsigned int x = 65536;
The value assigned is greater by 1 than the range. Here, the compiler starts again from beginning after
reaching the end of the range and the value 1 is assigned to x.
19. List the name of type modifiers.
Ans: The keywords signed, unsigned, short and long are type modifiers. A type modifier
changes the meaning of basic data type and produces a new data type. Each of these type modifiers
M02_ITL-ESL4791_02_SE_C02.indd 18 12/22/2012 4:59:42 PM