User Tools

Site Tools


k_r_chapter_7

K & R Study Questions for Chapter 7

Important Note

UNLESS SPECIFIED, DON'T USE THE XILINX SDK AS IT IS CONFIGURED TO USE A C++ COMPILER SO THAT IT WILL COMPILE FILES PORTED FROM ARDUINO C++ FILES FOR THE DISPLAY AND TOUCH CONTROLLER. Use rextester. When using rextester, you can paste the code of interest directly into the rextester window. Or, if you want to use gcc on your PC, you can use the instructions embedded in the comments of the file shown below.

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

The program:

int main() {
  char array[20];
  sprintf(array, "%s", "hello there!");
}

prints out hello there! when executed (T or F).

  • (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));
}
k_r_chapter_7.txt · Last modified: 2019/05/13 14:58 by hutch