Home
11.
What will the following program print?
#define MESG "COMPUTER BYTES DOG"
#include <stdio.h>
int main(void)
{
int n = 0;
while ( n < 5 )
printf("%s\n", MESG);
n++;
printf("That's all.\n");
return 0;
}

This is an ill-constructed program. Because the while statement doesn’t use braces, only the printf() statement is part of the loop, so the program prints the message COMPUTER BYTES DOG indefinitely until you can kill the program.

12.
Given that value is an int , what output would the following loop produce?
for ( value = 36; value > 0; value /= 2)
printf("%3d", value);
What problems would there be if value were double instead of int ?

It would produce the following output: 36 18 9 4 2 1

If value were double , the test would remain true even when value became less than 1. The loop would continue until floating-point underflow yielded a value of 0. Also, the %3d specifier would be the wrong choice.

13.
putchar(getchar()) is a valid expression; what does it do? Is getchar(putchar()) also valid?

The expression putchar(getchar()) causes the program to read the next input character and to print it; the return value from getchar() is the argument to putchar() . No, getchar(putchar()) is invalid because getchar() doesn’t use an argument and putchar() needs one.

14.
Suppose you have an executable program named count that counts the characters in its input. Devise a command-line command using the count program to count the number of characters in the file essay and to store the result in a file named essayct .

count <essay >essayct or else count >essayct <essay

15.
What is EOF ?

It’s a signal (a special value) returned by getchar() and scanf() to indicate that they have detected the end of a file.

16.
What is the difference between an actual argument and a formal parameter?

A formal parameter is a variable that is defined in the function being called. The actual argument is the value appearing in the function call; this value is assigned to the formal argument. You can think of the actual argument as being the value to which the formal parameter is initialized when the function is called.

17.
Is anything wrong with this function definition?
void salami(num)
{
int num, count;
for (count = 1; count <= num; num++)
printf(" O salami mio!\n"); }

Yes; num should be declared in the salami() argument list, not after the brace. Also, it should be count++ , not num++ .

18.
Which storage classes create variables local to the function containing them?

The automatic storage class, the register storage class, and the static, no linkage storage class.

19.
Which storage classes create variables that persist for the duration of the containing program?

The static, no linkage storage class; the static, internal linkage storage class; and the static, external linkage storage class.

20.
Which storage class creates variables that can be used across several files? Restricted to just one file?

The static, external linkage storage class. The static, internal linkage storage class.