369 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
Debargha Mitra Roy asked 6 days ago
67 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...
0 votes
0 votes
2 answers
3
Debargha Mitra Roy asked Apr 10
113 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
1 votes
1 votes
1 answer
4
SSR17 asked Feb 29
254 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