2_Answers_Strings_11

2_Answers_Strings_11 - CIS 15BG Answers Chapter 11: STRINGS...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Answers Chapter 11: STRINGS 1. One of the following 6 fragments of code is incorrect. Which one? F Why? name = "Tom"; // same as &name[0] = "Tom"; (A) (B) int num = 10; int num; num = 10; (C) (D) char *ptr = "Tom"; char *ptr; ptr = "Tom"; (E) (F) char name[10] = "Tom"; char name[10]; name = "Tom"; 2. There are four mistakes in the following program fragment. Identify and correct at least two. // Local Definitions char title[30]; char author[] = Donald E. Knuth ; // Statements // scanf( % 30 s , title ); scanf( % 29 s , title ); // 29 + 1 for '\0' FLUSH; // to discard the rest of the line printf( %-35s , title ); Title is more likely to consist of two or more words! scanf with " %29s" will read only one word! 3. Which function(s) can be called to read a string from the standard input device? a. getstr
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

2_Answers_Strings_11 - CIS 15BG Answers Chapter 11: STRINGS...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online