Solved

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

Posted on 2004-10-04
5
274 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
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 75 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

773 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