Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PRINTF
- 1. It will print 1st Argument on Screen (Except format Specifier %d , which will be Replaced )
- Syntax=> printf("arg1",arg2,arg3,.....,argn);
- 2. 1st Arg must be in pair of Double quotes ("").
- 3. If there is more than 1 arg, then those arg can be seperated by commas (,).
- Example:
- printf("hello") Semicolon (;) Syntax error
- printf("hello"); hello
- printf(" hello "); (space)hello(space)
- printf("hello %d",10); hello 10
- printf("hello %d hello %d %d",10,20,30); hello 10 hello 20 30
- 1st Format Specifier (%d) => 2nd Arg (10)
- 2nd FS => 3rd Arg
- 3rd FS => 4th Arg
- Nth FS => (N+1)Arg
- printf("%d%d%d",10,20,30); 102030
- printf("%d %d %d",10,20,30); 10 20 30
- printf("%d %d %d",10,20); 10 20 GV
- printf("%d %d %d",10); 10 GV GV
- printf("%d %d %d"); GV GV GV
- Note: For a given format Specifier if there is no arg, then result is Garbage Value(GV)
- Garbage value can any value stored by compiler.
- printf("%d %d",10,20,30,40); 10 20
- printf("%d",10+20); 30 here '+' act as Operator
- printf("10+20"); 10+20 here '+' is meant for printing
- printf("%d,%d",10,20); 10,20
- 1st Comma is for printing
- Next 2 Commas is for seperating arguments
- printf("%d + %d",2+0); 2 + Gv
- printf("%d * %d = %d",5,2,5+2); 5 * 2 = 7
- * Meant for printing
- + Meant for Adding values
- printf("%f",3.6); 3.600000
- printf("%d",3.0); Gv
- !X!X!X!X!X! Format Specifier Cannot convert the data from one type to another type. It just print only the data specified.
- printf("%f",3); Gv
- printf("%d",100.6); Gv
- printf("%f",5/2); Gv
- printf("%d",3.0/2); Gv
- printf("%f",3.0/2); 1.5
- printf("%f",3.0%2); Error ----> % does not act on float value
- printf("%f",-5%2); Gv
- printf("Hello","hai","bye"); hello
- >>> Since there is NO FORMAT SPECIFIER in 1st Arg, it does not go to the second arg.
- Exercise
- 1. printf(" %d ",0 ); 0
- 2. printf(" %f",-3); Gv
- 3. printf(" %d ",3/4/1); 0
- 4. printf(" %f",3+5*1); GV
- 5. printf(" %f ", 12-5.0*2 ); 2.0000000
- 6. printf(" %i",-3.0); GV
- 7. printf(" %f %i %c %d ",0.1,10,0,11); 0.1 10 GV 11
- 8. printf("%d %d %d", "%d %d" ,10 ,20 ,30 ,40 ,50); GV 10 20
- int amt=8500;
- 9. printf(amt); Error Absence of " "
- 10. printf(" %f ",amt-amt); GV
- 11. printf("amt"); amt
- 12. printf("%d",amt); 8500
- 13. printf("amt = %d"); amt = gv
- 14. printf("amt = %d",amt); amt = 8500
- 15. printf("%d+1000",amt); 8500+1000
- 16. printf("%d",amt+1000); 9500
- 17. printf(" amt+ 1000 " ); amt+1000
- 18. printf(" %d + %d = %d ",amt,amt,amt ); 8500 + 8500 = 8500
- 19. printf(" %d ",amt+500); 9000
- 20. printf(" amt = %d + %d",amt+100); amt = 8600 + GV
- 21. printf(" %d ",amt=amt+100); 8600
Add Comment
Please, Sign In to add comment