Study Guides (380,000)
US (220,000)
UMD (10,000)
CMSC (1,000)

CMSC 216 Study Guide - Midterm Guide: Scanf Format String, Octal

Computer Science
Course Code
CMSC 216
Larry Herman
Study Guide

This preview shows half of the first page. to view the full 2 pages of the document.
scanf(“%d”, &x);
“_%c” ignores any white space in front of string such as “____a” and
will read as “a”
%d - integer, %c - any character, %f - decimals(float)
New line is considered white space
scanf(“%d %d”, &x, &y);
printf(“x is %d, y is %d, x, y);
Input Output
2_3 x is 2, y is 3
2_3_4 x is 3, y is 3
__3___4 x is 3, y is 4
23_456 x is 23, y is 456
23Z_4 Error, but x is still 23
2, 3(on top of e<ch other) x is 2, y is 3
printf(“%d” , x);
12 bye
1234 bye
12 bye (field widths)
%4d - 4 is the total width
%04d - give 0 in front to match width
%2d, 1234 does not change the output even though the width is less
Input Output
printf(%5d” , 2); ____2
You're Reading a Preview

Unlock to view full version