C Programming - Library Functions - Discussion

Discussion Forum : Library Functions - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    char *i = "55.555";
    int result1 = 10;
    float result2 = 11.111;
    result1 = result1+atoi(i);
    result2 = result2+atof(i);
    printf("%d, %f", result1, result2);
    return 0;
}
55, 55.555
66, 66.666600
65, 66.666000
55, 55
Answer: Option
Explanation:

Function atoi() converts the string to integer.
Function atof() converts the string to float.

result1 = result1+atoi(i);
Here result1 = 10 + atoi(55.555);
result1 = 10 + 55;
result1 = 65;

result2 = result2+atof(i);
Here result2 = 11.111 + atof(55.555);
result2 = 11.111 + 55.555000;
result2 = 66.666000;
So the output is "65, 66.666000" .

Discussion:
6 comments Page 1 of 1.

Niky said:   1 decade ago
Why not taken 55.55 to 56 as in cell problem there was 2.5 as 3 not 2?

Deepika gupta said:   1 decade ago
@Prabakaran.

It's output is 10&i. Because in printf statement, only one access specifier is used for 2 integer value.

Prabakaran said:   1 decade ago
I have one Program. But I didn't know the answer. Can anyone please explain the program and the solving method. The program is,

main()
{
int a=10;
printf("%d &i",a,10);
}

Thomsika said:   1 decade ago
What is the difference between char and float?

Ashok Phour said:   1 decade ago
Float have 4 bytes but double have 8 bytes.
So any number 2.3 both represents its binary value in the 4 bytes and 8 bytes in different ways.

Float have 4 bytes 32-bit so in 4 bytes first byte have seven bit for store EXPONENT DATA bit 8th bit MANTISSA sign bit and remaining three bytes have 23 bit for MANTISSA DATA bit and 1 bit for EXPONENT sign bit.
Double have 8 byte so place the binary value in different way.so for the same value both have different bit placing and different values.

Sri said:   1 decade ago
What is the difference between float and double?

Post your comments here:

Your comments will be displayed after verification.