[Courses] [C] Beginner's Lesson 4A: Arrays, Qualifiers, and Reading Numbers

KWMelvin kwmelvin at intrex.net
Thu Oct 10 17:01:31 EST 2002

While playing around with some of this stuff I wondered what
would happen if I piped the output of the following little
program to `od' with the `-a' option?

	#include <stdio.h>
	int main(void)
		char name[] = "Bob";
		printf("%c", name[0]);
		printf("%c", name[1]);
		printf("%c", name[2]);
		printf("%c", name[3]);
		return 0;

Compile $ gcc -o prog prog.c -Wall -ansi -pedantic

Run $ ./prog | od -a


0000000   B   o   b nul

I just wanted to actually see that NUL at the end of the string,
and sure enough, there it is! 8^D

Happy Programming!

More information about the Courses mailing list