C: How to Program Chap. 2 Deitel 7th Edition

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

the conversion specifier _________ is used in a scan f format control string to indicate that an integer will be input and in a printf format control string to indicate that an integer will be output

%d

State a program that will calculate the product of three integers.

// Calculate the product of three integers

Identifier

A series of characters consisting of letters, digits, and underscores that does not begin with a digit.

Strings

A string is sometimes called a character string, a message, or a literal. The entire line, including the printf function (the f stands for "formatted"), its argument withing the parentheses and the semicolon, is called a statement. EVERY STATEMENT MUST END WITH A SEMICOLON!!!!!! (A.K.A. a statement terminator).

\a

Alert. Produces a sound or visible alert without changing the current cursor position.

\\

Backslash. Insert a backslash character in a string.

Assignment statement example: sum = int1 + int2;

Calculates the total of variables integer1 and integer2 and assigns the result to variable sum using the assignment operator =.

Whenever a new value is placed in a memory location, that value overrides the previous value in that location. This process is said to be ______.

Destructive

\"

Double quote. Insert a double-quote character in a string.

identify and correct - printf("The value is %d\n", &number);

Error: &number Correction: Eliminate the &

identify and correct - if (c => 7:) { printf("C is greater than or equal to 7\n"); }

Error: => is not an operator in C. Correction: The relational operator => should be changed to >=

identify and correct - if (c < 7); { printf("C is less than 7\n"); }

Error: Semicolon after the ) of the condition in the if statement. Correction: Remove the semicolon after the )

identify and correct - scanf("%d%d", &number1, number2);

Error: number2 does not have an & Correction: number 2 should be &number2

Comments cause the computer to display the text after // on the screen when the program is executed.

Falce. Comments do not cause any action to be performed when the program is executed. They're used to document programs and improve their readability.

A program that prints three lines of output must contain three printf statements.

False. A printf statement with multiple \n escape sequences can print sever lines.

Definitions can appear anywhere in the body of a function.

False. A variables definition must appear before its first use in the code.

All arguments following the format control srirng in a printf function must be preceded by an ampersand

False. Arguments in a printf function ordinarily should not be preceded by an ampersand. Arguments following the format control string in a scanf function ordinarily should be preceded by an ampersand.

C considers the variables number and NuMbEr to be identical.

False. C is case sensitive, so these variables are unique.

Function printf always begins printing at the beginning of a new line.

False. Function printf always begins printing where the cursor is position, and this may be anywhere on a line of the screen.

The arithmetic operators *, /, %, + and - all have the same level of procedure.

False. The operators *, / and % are on the same level of precedence, and the operators + and - are on a lower level of precedence

\t

Horizontal tab. Move the cursor to the next tab stop.

The ____________ statement is used to make decisions.

If

Variables

Locations in memory where values can be stored for use by a program

Every C program begins execution at the function _______.

Main

\n

Newline. Position the cursor at the beginning of the next line.

When a value is read from a memory location, the value in that location is preserved; this process is said to be__________.

Nondestructive

Escape sequences

The backslash is an escape character. It indicates that printf is supposed to do something out of the ordinary.

scanf("%d", &integer1);

The first, the format control string, indicates the type of data that should be entered by the user. The %d conversion specifier indicates that the data should be an integer (the letter d stands for "decimal integer"). The % in this context is treated by scanf as a special character that begins a conversion specifier. The second argument of scanf begins with an ampersand(&)---- called the address operator--- followed by the variable name.

All variables must be defined before they're used.

True

All variables must be given a type when they're defined.

True

The escape sequence \n when used in a printf format control string causes the cursor to position to the beginning of the next line on the screen.

True

The remainder operator (%) can be used only with integer operands.

True

Prompt

a message that tells the user to take a specific action.

Adding comments to code

begin a comment with // indicating that these two lines are comments. you insert comments to document programs and improve program readability

Left brace, {

begins the body of every function. A corresponding right brace ends each function. This pair of braces and the portion of the program between the braces is called a block.

If number is not equal to 7, print "The variable number is not equal to 7."

if (number != 7) { printf("The variable number is not equal to 7\n"); }

Output statement, printf("Quizlet");

instructs the computer to perform an actions, namely to print on the screen the string of characters marked by the quotation marks.

Define the variables c, thisVariable, q76354 and number to be type of int.

int c, thisVariable, q76354, number;

Define the variables x, y, z and result to of type int.

int x, y, z result;

preprocessor directives, #include<stdio.h>

is a directive to the C preprocessor. tells the preprocessor to include the contents of the standard input/output header(<stdio.h>) in the programs

Every functions body begins with ______ and ends with________.

left brace { and right brace }

The escape sequence \n represents the ________ character, which causes the cursor to position to the beginning of the next line on the screen.

newline

scanf function

obtains the value from the user. Reads from the standard input.

The main function, int main(void)

part of every C program. the parentheses after main indicate that main is a program building block called a function.

The __________ standard library function displays information on the screen.

printf

Prompt the user to enter an integer. End your prompting message with ; followed by a space and leave the cursor positioned after the space.

printf("Enter an integer:");

Prompt the user to enter three integers.

printf("Enter three integers:");

Print "The product is" followed by the value of the integer variable result.

printf("The product is: ("%d\n", result);

Print the message "This is a C program." on one line.

printf("This is a C program.\n");

Print the message "This is a C program." on two lines so that the first line ends with C.

printf("This is a C\nprogram.\n");

Print the message "This is a C program." with each word on a separate line.

printf("This\nis\na\nC\nprogram.\n");

Print the message "This is a C program." with the words separated by tabs.

printf("This\tis\ta\tC\tprogram\n");

Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result.

result = x * y * z;

The ________ standard library function is used to obtain data from the keyboard.

scanf

Read an integer from the keyboard and store the value entered in integer variable a.

scanf("%d", &a);

Read three integers from the keyboard and store them in the variables x, y and z.

scanf("%d%d%d", &x, &y, &z);

Every statement ends with a _________.

semicolon ;


Ensembles d'études connexes

Risk assessment and decision support

View Set

11.2.10 - Manage files from cmd line - Practice Questions

View Set

ATI Chapter 64 Osteoarthritis and Low-Back Pain

View Set

Chapter 18: Breasts, Axillae, and Regional Lymphatics

View Set

CWTS-11-Performing an RF Wireless LAN Site Survey, itsp215/itsp216

View Set

Chapter 67: Management of Patients With Cerebrovascular Disorders

View Set

Audit of Cash and Financial Instruments

View Set

Med Surg II: Final Exam (Questions on Spring 2024 Final Exam)

View Set