Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sizeof() O/P

Reply
Thread Tools

sizeof() O/P

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-25-2005
Jan Engelhardt <> writes:
>>i'm surprised at the output of the following code. compiled in turbo C
>>
>>void main()
>>{
>>printf("%d",sizeof(printf());
>>}
>>the output was : 2

>
> Given that <stdio.h> was included, the return type of printf is int,
> and an int in turbo C is a 16-bit entity.


Given that <stdio.h> *wasn't* included, the compiler assumes that any
unrecognized function returns an int. See my other response on this
thread.

>>how come the output is 2? actually what is the property of sizeof()

>
> Try again on a modern compiler and you should get 4.


It depends on the system.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      12-26-2005
Jan Engelhardt said:

> Given that <stdio.h> was included, the return type of printf is int,
> and an int in turbo C is a 16-bit entity.
>
>>how come the output is 2? actually what is the property of sizeof()

>
> Try again on a modern compiler and you should get 4.


<sigh>
All the world's a PC running a 32-bit compiler.
</sigh>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57