352 views
4 votes
4 votes
 

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;
}
  A.
4  
  B.
8
  C.
16
  D.
22

2 Answers

0 votes
0 votes

the answer is for 16bit platform of Turbo C

(int)(float)(char) i;
it runs like that
typecast i into char first which is of 1 byte. 
: 1 byte<-(char) i
than in float
: 4 byte <- char variable i(size is 1 byte)
than in int
: 2 byte<- float variable i(size is 4 byte)
so finally i is of 2 byte integer variable

0 votes
0 votes

answer is : (A)  4 

for the 64-bit system (the size of integer is 4)

first typecasting of i is done from double to char 

and then from char to float 

and then float to int

then the final size of the i will be 4 (the size of int )

answer may be 2(the size of int) if your system is of 32-bit configuration.

Related questions

0 votes
0 votes
1 answer
1
SSR17 asked Feb 29
205 views
#include <stdio.h int main() { int i = -1; int x = (unsigned char)i; printf("%d", x); return 0; }output is 255 , but please explain how
2 votes
2 votes
1 answer
2
rupamsardar asked Aug 30, 2023
468 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
5 votes
5 votes
2 answers
3
saurabh0709 asked Aug 1, 2023
1,136 views
What will be the output of the following code? _______ #include <stdio.h int main(){ char val=250; int ans; ans= val+ !val + ~val + ++val; printf("%d", ans); return 0; }
2 votes
2 votes
1 answer
4