C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 2)
2.
What will be the output of the program in DOS (Compiler - Turbo C)?
#include<stdio.h>
double i;

int main()
{
    (int)(float)(char) i;
    printf("%d", sizeof((int)(float)(char)i));
    return 0;
}
1
2
4
8
Answer: Option
Explanation:
Due to the C language is being platform dependent:

In Turbo C (DOS - 16 bit platform), the output will be 2.

But in GCC (Unix/Linux - 32 bit platform), the output will be 4.
Discussion:
19 comments Page 2 of 2.

Suresh said:   1 decade ago
I gets cast to a char, then to a float and finally to an int whose size is then used in sizeof. In Turbo C int is 2 bytes.

Raja said:   2 decades ago
The option does not matches with the answer of the online compiler which is giving the answer as 4.

Why?

Himanshu said:   1 decade ago
What the meaning of these three declaration... which is consider by compiler... int, char, float?

Archana said:   1 decade ago
But look at the declaration of I globally at the top. What does it signify in the pgm?

Sasi said:   1 decade ago
Can you please explain (int) (float) (char) i this statement?

Naresh said:   10 years ago
Is it possible to convert float (4 bytes) to int (2 bytes)?

Shri said:   1 decade ago
Very good explanation kapilsuman. Kudos to you.

Kaleem said:   1 decade ago
That right way to explain.... weldn kapilsuman

Pavan Kumar said:   9 years ago
What is typecasting?


Post your comments here:

Your comments will be displayed after verification.