Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
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…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

821 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