473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

%u printf

#include<stdio.h>
int main()
{
int i;
printf("\n%u%u",sizeof(i));
}

output 42433316

plz explain the output
with 1 %u o/p =4bytes
with 2 %u o/p=42433316 ????

Aug 20 '06 #1
6 16748
saurabh wrote:
#include<stdio.h>
int main()
{
int i;
printf("\n%u%u",sizeof(i));
Here you tell printf to expect two more parameters, but you only pass one.
}

output 42433316

plz explain the output
Please use real words.
with 1 %u o/p =4bytes
with 2 %u o/p=42433316 ????
The first 4 is the valid output, the rest is undefined garbage.

--
Ian Collins.
Aug 20 '06 #2

"Ian Collins" <ia******@hotmail.comha scritto nel messaggio
news:4k************@individual.net...
saurabh wrote:
#include<stdio.h>
int main()
{
int i;
printf("\n%u%u",sizeof(i));

Here you tell printf to expect two more parameters, but you only pass one.
}

output 42433316

plz explain the output

Please use real words.
with 1 %u o/p =4bytes
with 2 %u o/p=42433316 ????
The first 4 is the valid output, the rest is undefined garbage.
Moreover "%u" is valid in order to print unsigned int.

printf("%u\n",(unsigned int)sizeof(i));

size_t can be "bigger" than unsigned int.

In C99 you can use %zu for size_t.

printf("%zu\n",sizeof(i));

--
Giorgio Silvestri
DSP/Embedded/Real Time OS Software Engineer


Aug 20 '06 #3
On Sun, 20 Aug 2006 19:32:14 UTC, "saurabh" <ro***********@gmail.com>
wrote:
#include<stdio.h>
int main()
int main(void)
{
int i;
printf("\n%u%u",sizeof(i));
}

output 42433316
You're multiple times in undefined behavior:
1. You use uninitialised i.
2. You use more conversion flags in the format string as defined in
actual parameters.
3. sifeof returns type size_t not unsigned int.

Another error is that you lets mis the '\n' immediately before the
format string ends.

The output of your program means nothing. It is completely random
based on the errors. Undefined behavior means that all and anything
one can thing about may occure.

I've seen seldom so manny errors in so little number of lines of code.

Fix all the errors and try again.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
Aug 22 '06 #4
Herbert Rosenau wrote:
On Sun, 20 Aug 2006 19:32:14 UTC, "saurabh" <ro***********@gmail.com>
wrote:
>#include<stdio.h>
int main()

int main(void)
>{
int i;
printf("\n%u%u",sizeof(i));
}

output 42433316

You're multiple times in undefined behavior:
1. You use uninitialised i.
2. You use more conversion flags in the format string as defined in
actual parameters.
3. sifeof returns type size_t not unsigned int.
While #2 and #3 are indeed undefined, there is nothing undefined about
#1 (Note, that the OP doesn't use the *value* of i)
--
Clark S. Cox III
cl*******@gmail.com
Aug 22 '06 #5
Herbert Rosenau wrote:
On Sun, 20 Aug 2006 19:32:14 UTC, "saurabh" <ro***********@gmail.com>
wrote:

>>#include<stdio.h>
int main()


int main(void)

>>{
int i;
printf("\n%u%u",sizeof(i));
}

output 42433316


You're multiple times in undefined behavior:
1. You use uninitialised i.
No; sizeof does not evaluate its operand.
[...]
--
Eric Sosman
es*****@acm-dot-org.invalid
Aug 22 '06 #6
2006-08-22 <wm***************************@JUPITER1.PC-ROSENAU.DE>,
Herbert Rosenau wrote:
On Sun, 20 Aug 2006 19:32:14 UTC, "saurabh" <ro***********@gmail.com>
wrote:
>#include<stdio.h>
int main()

int main(void)
>{
int i;
printf("\n%u%u",sizeof(i));
}

output 42433316

1. You use uninitialised i.
so?

You're right about the rest, though.
Aug 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
8
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
29
by: whatluo | last post by:
Hi, c.l.cs I noticed that someone like add (void) before the printf call, like: (void) printf("Timeout\n"); while the others does't. So can someone tell me whether there any gains in adding...
4
by: pai | last post by:
Hi , Can any one tell me how this statement of printf is behaving . how the last digit is printed int a=2,b=4,c=7; printf("%d",printf("%d %d:",a,b)); //answer to this was 2 4:3
11
by: timmu | last post by:
Someone asked me a question about integer division and printf yesterday, I tell him he should do a casting to float/double before you do any interger division. But he doesn't think so, so I try...
19
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement,...
34
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
1
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.