The rst argument is a format string while any

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t, and declares a variable ip of this type. Alternatively, we could declare this variable directly as: 2.1. INFORMATION STORAGE 29 code/data/show-bytes.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <stdio.h> typedef unsigned char *byte_pointer; void show_bytes(byte_pointer start, int len) { int i; for (i = 0; i < len; i++) printf(" %.2x", start[i]); printf("\n"); } void show_int(int x) { show_bytes((byte_pointer) &x, sizeof(int)); } void show_float(float x) { show_bytes((byte_pointer) &x, sizeof(float)); } void show_pointer(void *x) { show_bytes((byte_pointer) &x, sizeof(void *)); } code/data/show-bytes.c Figure 2.3: Code to Print the Byte Representation of Program Objects. This code uses casting to circumvent the type system. Similar functions are easily defined for other data types. 30 int *ip; End CHAPTER 2. REPRESENTING AND MANIPULATING INFORMATION New to C? The printf function (along with its cousins fprintf and sprintf) provides a way to print information with considerable control over the formatting details. The first argument is a format string, while any r...
View Full Document

Ask a homework question - tutors are online