740 views
3 3 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 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 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.

Position:
Show:

Related questions

1 1 vote
1 1 answer
293
293 views
khanshahima4 asked Sep 24
293 views
1. If precedence tells me which operator has priority, and associativity tells me how to handle operators at the same level, then why do I need a separate concept called ...
14 14 votes
1 1 answer
1.4k
1.4k views
GO Classes asked Jul 2
1,359 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
18 18 votes
2 2 answers
756
756 views
GO Classes asked Jul 2
756 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
10 10 votes
1 1 answer
563
563 views
GO Classes asked Jul 2
563 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...