cs16wk02c

cs16wk02c - Formatted printing with printf printf Formatted...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Formatted printing with Formatted printing with printf printf z Basic form: printf("format",object1,object2,…) printf("x = %d", x); /* same as %i ; x is an integer */ –O r u s e %o or %x to show same value in octal or hexadecimal – And unique to ch translator - %b to show in binary z Use %c to print character representation of int or char printf("%c", 65); /* prints A */ – See ~mikec/cs16/demo02/p2_1.c z %f or %e or %g for floating point, and %s for strings – Also control field width, precision, and other formatting printf("%-9s %7.2f \n", "Value", v);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
z Require escape sequences – all start with \ – e.g., '\n' – newline, and '\t' –tab –A l so '\"' – double quotes, and '\'' – single quote '\\' – back slash itself, and more (see text p. 54) – Play with hello.c – to see effects z By the way, comments are important to humans /* I am a comment. I explain part of the code. */ /* A particularly long comment, like this one, may span lines (but don’t try to nest them). */ printf(/*
Background image of page 2
Assignment Assignment = is the assignment operator – It does not mean “equals” (but we say it like that) z e.g., x = 5;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CMPSC 16 taught by Professor Costanzo during the Spring '11 term at UCSB.

Page1 / 13

cs16wk02c - Formatted printing with printf printf Formatted...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online