in Programming in C edited by
2,087 views
2 votes
2 votes

What is the output of the following $C$-program

main()
{
    printf("%d %d %d",size of (3.14f), size of (3.14), size of (3.141));
}
  1. 4 4 4
  2. 4 8 10
  3. 8 4 8
  4. 8 8 8
in Programming in C edited by
2.1k views

4 Comments

A should be the correct answer.
1
1
i think the answer will be

4,8,8

but it doesnt matches with any of the options above .
2
2
0
0

6 Answers

1 vote
1 vote
4 8 8

Float occupies 4 bytes and double occupies 8 bytes, and long double occupes 8 bytes

Here none of option matches....howz it possible

2 Comments

double and long double are both 8 bytes?
0
0
No!

on my platform:

# double = 8 Bytes

# long double = 16 bytes
0
0
1 vote
1 vote
answer is: D

Float occupies 8 bytes and double occupies 8 bytes, and long double occupes 8 bytes..

its also depends of compiler ..
0 votes
0 votes
3.14f means floating point value---> so 4

3.14 is by default double hence----->8

3.141 is also by default double hence---->8

So 4 8 8 (using GNU GCC compiler)
0 votes
0 votes

the answer is 4 8 8 (which is not there in options)

"By default,floating constant are stored as double precision numbers.To force the compiler to store a floating constant in floating format,put the letter f(or F) and in long double format put the letter l(or L) at the end "

now 3.14f is stored as float since f is specified at the end ...4 bytes(compiler dependent ofcourse)

3.14,3.141 are stored as double since  no letter at the end.....8 bytes,8 bytes

 

3 Comments

Can you give any reference for sizeof float being compiler dependent?
1
1
from dennis ritchie book
from kn king book

Arjun sir,please correct me if I am wrong.

1
1
yes, that is correct. Unless IEEE format is specified.
1
1

Related questions