Solved

WHats the output of printf(" %u",function)

Posted on 2004-10-04
5
248 Views
Last Modified: 2010-08-05


printf(" %u",fun);

where fun was a function with the void type and more interestingly the function is written without "()" in the above printf statement.

What will be the output and why?
0
Comment
Question by:thebeseus
  • 3
5 Comments
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 50 total points
Comment Utility
it's the address of the function in unsigned integer format.
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
everything is associated with an address in memory.
0
 
LVL 12

Expert Comment

by:stefan73
Comment Utility
Hi thebeseus,
functions without () are passed as addresses. fun and &fun are the same.

Cheers!

Stefan
0
 
LVL 22

Accepted Solution

by:
grg99 earned 75 total points
Comment Utility
Good question.  

You're going to get some number printed.
Only two things to say about this:

(1)  "fun" without the "()" means the ADDRESS of fun.

(2)  Printing out an address in %u format  is not guarateed to do the right thing.
It will work on computers where an unsigned int happens to be the same size as an address, which includes x86 in real mode, small memory model, or x86 32-bit mode.   Otherwise the number printed is going to be incorrect.

0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
thebeseus,
    your question is answered. Do you need further assistance?

hongjun
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now