By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

How the following C program works?

itiger
P: 12
Expand|Select|Wrap|Line Numbers
  1. # include <stdio.h>
  2. void main()
  3. {
  4.    char str[] = "Zingle Bell Zingle Bell";
  5.    printf("%.#s %.2s", str, str);
  6. }
  7.  
output:
#s Zi

(how the '%s' type specifier works in this case.)
Sep 3 '10 #1
Share this Question
Share on Google+
1 Reply


100+
P: 542
I cannot find any reference meaning for %.#s or why fprint would output #s which may be printed as a result of undefined behavior. %.2s is applying two places of precision to string str and so prints Zi bearing in mind that a character is treated like an int.
Sep 14 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.