- Home
- Interview Questions
- C Programming
#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.
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.
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.
count <essay >essayct or else count >essayct <essay
It’s a signal (a special value) returned by getchar() and scanf() to indicate that they have detected the end of a file.
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.
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++ .
The automatic storage class, the register storage class, and the static, no linkage storage class.
The static, no linkage storage class; the static, internal linkage storage class; and the static, external linkage storage class.
The static, external linkage storage class. The static, internal linkage storage class.