Solution for Exercise 6-7
ex0607
#include <stdio.h>
int main()
{
int shadrach, meshach, abednego;
shadrach = 701;
meshach = 709;
abednego = 719;
printf("Shadrach is %d\nMeshach is %d\nAbednego is %d\n",shadrach,meshach,abednego);
return(0);
}
Output
Shadrach is 701
Meshach is 709
Abednego is 719
Notes
* Above you see the same code as shown in the book, without wrapping the text.
* Here is the same code, with the \ character used to split the long printf() statement:
#include <stdio.h>
int main()
{
int shadrach, meshach, abednego;
shadrach = 701;
meshach = 709;
abednego = 719;
printf("Shadrach is %d\nMeshach is %d\nAbednego is %d\n",\
shadrach,meshach,abednego);
return(0);
}
* The \ (backslash) and the blanks that begin Line 11 are ignored by the compiler. They exist outside of double quotes, so they're considered white space.
* You can also fashion the printf() statement like this:
#include <stdio.h>
int main()
{
int shadrach, meshach, abednego;
shadrach = 701;
meshach = 709;
abednego = 719;
printf("Shadrach is %d\nMeshach is %d\nAbednego is %d\n",
shadrach,
meshach,
abednego);
return(0);
}
* The construction above doesn't need a backslash. Again, the new line and spaces after the comma (at Line 10) are ignored by the compiler; they're white space. I've also set each variable on a line by itself. For a complex printf() statement, such formatting is blessed relief — and quite readable.
* Remember to close the parentheses and end the statement with a semicolon, especially when it's split across multiple lines.
* And, of course, you could have used three printf() functions on three statements to do the same thing. As is usually the case, you'll find multiple solutions to programming exercises in C.
Copyright © 1997-2025 by QPBC.
All rights reserved
