Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-04
5
Medium Priority
?
302 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 150 total points
ID: 12215694
it's the address of the function in unsigned integer format.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 12215696
everything is associated with an address in memory.
0
 
LVL 12

Expert Comment

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

Cheers!

Stefan
0
 
LVL 22

Accepted Solution

by:
grg99 earned 225 total points
ID: 12215981
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
ID: 12215991
thebeseus,
    your question is answered. Do you need further assistance?

hongjun
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

876 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