Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

863 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

27 Experts available now in Live!

Get 1:1 Help Now