C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 8)
8.
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(i));
    return 0;
}
4
8
16
22
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 1 of 2.

Swathi said:   2 decades ago
Can any one explain this?

Kickem said:   1 decade ago
In the line <(int)(float)(char) i;> the casts do not modify the type of the variable i, so i is still a Double stored 8 bytes.

Raj said:   1 decade ago
Initially i is declared as double. So i=8 .

Ramanathan said:   1 decade ago
What is the difference between these two
(float) i; and
float i;

It produce the size as 8 and 4 respectively.?

Wikiok said:   1 decade ago
(float) i : Is not a declaration, but a cast. You need an lvalue too. It doesn't change the sizeof(i).
float i : It is a declaration. sizeof(i) = 4 (32bit platform)

Prathyusha said:   1 decade ago
GUD EXPLANATION!.....@Kickem

Kannan said:   1 decade ago
#include<stdio.h>
double i;

int main()
{
(int)(float)(char) i;
printf("%d",sizeof(i));
return 0;
}

Theja said:   1 decade ago
@Wikiok...Thanks for explanation

R@hit said:   1 decade ago
I am satisfied with Kickem's explanation.

In this program the line
(int)(float)(char) i;........... is useless

If you compile the program then find that compiler say's that "Code has no effect" and highlight this line.

In this program the compiler print the size of double which is declared global in the program.

If you want to check that how it is true then you will replace double to the int or float you find that it print's the size of int or float.

Write the program like

#include<stdio.h>
int i;

int main()
{
(int)(float)(char) i;
printf("%d",sizeof(i));
return 0;
}

Output is : 2

Thank you friends if you have more questions the contact me in gmail.com my email-id is : rk52567(at)gmail.com

ROHITH said:   1 decade ago
Thanks @ROHIT.


Post your comments here:

Your comments will be displayed after verification.