Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
printf() Function
What is the output of printf("%d")?
✍: Guest
1. When we write printf("%d",x); this means compiler
will print the value of x. But as here, there is
nothing
after "%d", so compiler will show in output window
gurbage value.
2. When we use %d the compiler internally uses it to
access the argument in the stack (argument stack).
Ideally compiler determines the offset of the data
variable depending on the format specification string.
Now when we write printf("%d",a) then compiler first
accesses the top most element in the argument stack of
the printf which is %d and depending on the format
string it calculated to offset to the actual data
variable
in the memory which is to be printed. Now when only %d
will be present in the printf then compiler will
calculte the correct offset (which will be the offset
to access the integer varible) but as the actual
data objet is to be printed is not present at that
memory location so it will print what ever will
be the contents of that memory location.
3. Some compilers check the format string and will
generate an error without
the proper number and type of arguments for things
like printf(...) and scanf(...).
2007-02-26, 8240👍, 0💬
Popular Posts:
What Is URI? URI (Uniform Resource Identifier) is a superset of URL. URI provides a simple and exten...
Have you ever worked with Microsoft Application Blocks, if yes then which? Application Blocks are C#...
What is the benefit of using #define to declare a constant? Using the #define method of declaring a ...
Once I have developed the COM wrapper do I have to still register the COM in registry? Yes.
Can you explain why your project needed XML? Remember XML was meant to exchange data between two ent...