K & R Chapter 7 Study Questions

  1. (T or F) The value for EOF is typically -1.
  2. (T or F) Standard output comes from the keyboard.
  3. (T or F) For #include searches, the gcc compiler searches for fileName only in the directory where the program is located.
  4. (T or F) caseUpper() is the name of the function that can be used to convert a character to upper case.
  5. (T or F) For printf(), the formatting argument G may generate the same results as the formatting argument f.
  6. (T or F) printf("%.*s", 5, "hello there\n"); prints out hello.
  7. (T or F) printf("%d\n", 3.0); prints out 3.0000.

  8. The following program prints out hello there! when executed (T or F). c int main() { char array[20]; sprintf(array, "%s", "hello there!"); }
  • (T or F) sscanf() reads characters from standard input.
  • What does the following program print when executed and when you type 2 2 2 and press enter (or carriage return).

      #include <stdio.h>
    
      int main() {
        int month, day, year;
        printf("%d\n", scanf("%d %d %d", &month, &day, &year));
      }
    
  • What does the following program print when executed? Why?
    #include <stdio.h>
    #include <string.h>
    #define LENGTH 100
    int main() {
    char string1[LENGTH] = "hello ";
    char string2[LENGTH] = "there";
    strcpy(string1, string2);
    printf("%s\n", string1);
    }
    
  • What does the following program print when executed? Why?
    #include <stdio.h>
    #include <string.h>
    #define LENGTH 100
    int main() {
    char string1[LENGTH] = "hello ";
    char string2[LENGTH] = "there";
    strcat(string1, string2);
    printf("%ld\n", strlen(string1));
    }
    
  1. What does the program below print out?
    int main() {
        int i=9;
        int j = ((0 > 1) && (i=14));
        printf("%d\n", i);
    }
    
  2. What does the program below print out?
    int main() {
        int i=9;
        int j = ((0 > 1) || (i=14));
        printf("%d\n", j);
    }