CS1313 final exam study guide

Ace your homework & exams now with Quizwiz!

GIVE AN EXAMPLE of a character string literal constant.

"This is a printf.\n"

Write a complete program that: declares an integer variable, reads a value from the keyboard into that variable, writes to standard output the square of the variable's value

#include <stdio.h> int main () { int num; scanf("%d", &num); printf("%d", num*num); return 0; }

Write a complete program that: declares an integer variable, reads a value from the keyboard into that variable, writes to standard output the square of the variable's value, twice the value and the square of the value separated by spaces

#include <stdio.h> int main () { int v; scanf("%d", &v); printf("%d %d %d", v, v*2, v*v); return 0; }

CHANGE THE ORDER of the lines below so that the program outputs meaningful output. You MUST use EVERY SINGLE LINE SHOWN BELOW. printf("Let me guess your age!\n"); } /* main */ scanf("%f", &age_in_years); printf("I'd guess that your age is %f years.\n", { /* main */ printf("What is your age in years?\n"); int main () #include <stdio.h> float age_in_years; age_in_years);

#include <stdio.h> int main () { /* main */ float age_in_years; printf("Let me guess your age!\n"); printf("What is your age in years?\n"); scanf("%f", &age_in_years); printf("I'd guess that your age is %f years.\n", }/*main*/

CHANGE THE ORDER of the lines below so that the program outputs thatthe mass is 5.75 kilograms. You MUST use EVERY SINGLE LINE SHOWN BELOW. } /* main */ int main () mass_in_kg = 10.5; printf("Mass: %f kg\n", mass_in_kg); { /* main */ Float mass_in_kg; #include <stdio.h> mass_in_kg = 5.75;

#include <stdio.h> int main () { /* main */ Float mass_in_kg; Int mass_in_kg = 5.75; mass_in_kg = 10.5; printf("Mass: %f kg\n", mass_in_kg); }/*main*/

WRITE the shortest possible VALID C program. (Here, valid means acceptable to the compiler. The program does not have to be useful, nor does it have to follow any of this course's rules for programming projects.) What does it do when you run it?

#include <stdio.h> int main () { /* main */ printf("Hello. \n"); } /* main */

Write an expression that computes the average of the values 12 and 40

(12+40)/2

WHAT IS THE OUTPUT of each of these programs? Examine the programs CAREFULLY. You do not need to include extraneous blank spaces in your answer. If a program will not compile, mark WON'T COMPILE and EXPLAIN. If a program compiles and runs but does not produce any output, mark NO OUTPUT and EXPLAIN. If a program compiles and runs but produces garbage output, mark GARBAGE and EXPLAIN. If you are not confident of your answer, type in, compile and run the programs.

(a) #include <stdio.h> int main () { /* main */int woopdedoo; woopdedoo = 127; printf("%d\n", woopdedoo); } /* main */ 127 (b) #include <stdio.h> int main () { /* main */int yippee = 127;printf("yippee = %d\n", yippee); } /* main */ yippee=127 (c) #include <stdio.h> int main () { /* main */int oyvey = 127; oyvey = 128; printf("oyvey = %d\n", oyvey); } /* main */ oyvey=128 (d) #include <stdio.h> int main () { /* main */int ladeedah; printf("%d\n", ladeedah); } /* main */ no output, ladeedah was not assigned a value

WHAT IS THE NAME of each of the following C constructs:

(a) /* start of comment, comment delimiter (b) */ end of comment, comment delimiter (c) /* What is this? */ comment (d) { start of block, block open (e) } end of block, block open (f) #include <stdio.h> preprocessor (g) int main () main function header (h)printf("Hello, world!\n");printf statement

WHAT IS THE DATA TYPE of each of the following literal constants? If the item ISN'T a valid literal constant, mark it INVALID and EXPLAIN.

(a) 2004982098 valid int literal constant (b) 2004982098.0 invalid, decimal point (c) 2,004,982,098 invalid, commas (d) -2004982098 valid int literal constant (e) --2004982098 invalid, two signs (f) 2004982098- invalid, sign must come before the number (g) -3529.3098e+10 invalid, decimal point (h) -3529.3098e-10 invalid, decimal point (i) 2e-05 invalid, decimal point (j) 2.0e-05 invalid, decimal point (k) 0 valid int literal constant

NAME TWO EXAMPLES of magnetic secondary storage media, and give an advantage and a disadvantage of each: Spinning disk drive and credit cards

(a) Advantage: always can be read Disadvantage: contents can degrade overtime (b) Advantage: don't degrade much overtime Disadvantage: can be erased by magnets

NAME TWO EXAMPLES of solid state secondary storage media, and give an advantage and a disadvantage of each: Floppy disk and flash drive

(a) Advantage: always can be read Disadvantage: expensive per MB (b) Advantage: contents don't degrade much over time Disadvantage: can't be erased by magnates

NAME TWO EXAMPLES of optical secondary storage media, and give an advantage and a disadvantage of each: DVD and CD

(a) Advantage: always can be read Disadvantage: some can be written only once (b) Advantage: cant be erased by magnets Disadvantage: contents degrade e.g. being scratched

WHAT are the three major categories of hardware that computers typically have?

(a) CPU (b) Storage (c) I/O

Unix Questions: Give the Unix commands to accomplish the following tasks

(a) CREATE A COPY of an existing file named whoopdedoo.txt that is in your current working directory, so that the copy is named tapioca.txt and is also in your current working directory. cp whoopdedoo.txt (b) EDIT an existing text file named want editing.txt that is in your current work- ing directory. nano want_editing.txt (c) EDIT a non-existent text file named want editing too.txt that will be in your current working directory. nano editing_too.txt (d) MAKE an executable named my program from a C source file named my program.c that are both in your current working directory. (Assume that an appropriate makefile entry is already in your makefile.) make my_program (e) EXECUTE (that is, run) a program named this is it that is in your current working directory. this_is_it

WHAT is the SPEED in MB/sec, the MAXIMUM SIZE in GB and the PRICE per MB of the following storage media on a current PC

(a) Cache 40,000MB/sec, 32MB, $27.0000000/MB (b) RAM 12,5000MB/sec, 3,145,728MB, $0.0055800/MB (c) hard disk 100MB/sec, 15,000,000MB, $0.0000225/MB (d) USB 3 flash drive 625MB/sec, 512,000, $0.0001640/MB (e) CD-RW 7.8MB/sec, 700MB, $0.0006271/MB (f) DVD-RW 32MB/sec, 4,700MB, $0.0000424/MB (g) floppy disk 0.03, 1.44MB,/sec, 1.44MB, $1.9100000/MB

Compare print to scanf.

(a) Does it OUTPUT or INPUT? printf: output scanf: input (b) TO/FROM WHERE does it output/input? printf: outputs to standard output scanf: inputs from stdin (c) Its string literal CAN or CANNOT contain literal text (other than a single blank space as a separator between each set of multiple placeholders)? printf: can scanf: can't (d) Its string literal CAN or CANNOT contain a newline (for example, at the end of the string literal)? printf: can scanf: can't (e) The variable name(s) associated with placeholder(s) MUST or CANNOT be preceded by an ampersand (&)? printf: can't scanf: can

When data and instructions reside in the following kinds of storage, WHEN are they expected to be used?

(a) Registers- data actively being used (b) Cache- data that has just been used or is about to be used (c) Main memory- when they're being used by a program currently running (d) Secondary storage- data that will be used in the future

NAME three output devices (you are not limited to the ones listed in the lecture notes, but your choices must fit the definition).

(a) Speaker (b) Printer (c) Monitor

NAME TWO THINGS that every main memory location has.

(a) address (b) value

NAME THREE EXAMPLES of operating systems.

(a) android (b) Microsoft windows (c) Mac OS

NAME TWO DIFFERENCES between a bit and a byte.

(a) bytes are addressable whereas a bit isn't (b) bytes are a collection made up of 8 bits

WHAT are the two categories of primary storage that computers typically have?

(a) cache (b) RAM

NAME TWO DIFFERENCES between main memory and cache.

(a) cache is fast while RAM is slow (b) Cache is very expensive whereas RAM is less expensive

WHAT do each of the following Unix commands do?

(a) cat create files (b) make determine what parts need to be recompiled (c) pwd show the working directory (d) ls list files (e) cp copy (f) mkdir create directory (g) cd changes the current working directory (h) nano edit a file (i)scriptsequence of commands

Numeric literal constants can be used in several ways, some of which are good programming practice and some of which are bad programming practice. MARK each of the following uses as either GOOD or BAD.

(a) const int feet per fathom = 6; good (b) float height in m = 1.6; bad (c) snow depth in inches = 2; bad (d) degrees fahrenheit = degrees celsius * (9.0 / 5.0) + 32.0; good

WHAT THREE COMPONENTS does every language have?

(a) grammar (b) symbols (c) semantics

WHAT are the two categories of I/O devices that computers typically have?

(a) input devices (b) output devices

NAME THREE EXAMPLES of programming languages.

(a) java (b) python (c) C

NAME three input devices (you are not limited to the ones listed in the lecture notes, but your choices must fit the definition).

(a) keyboard (b) joystick (c) mouse

NAME TWO DIFFERENCES between magnetic media and solid state media.

(a) magnetic media can be erased by a magnet, solid state media can't (b) solid state media contents don't degrade over time, magnetic media contents do

WHAT are the two categories of storage that computers typically have?

(a) main memory (b) cache

NAME THREE DIFFERENCES between natural languages and programming languages

(a) natural language can be ambiguous, programming language can't (b) natural language can be flexible, programming language can't (c) natural language can incorporate multiple languages, programming language can't

NAME TWO DIFFERENCES between magnetic media and optical media.

(a) no every type of optical media can be rewritten, magnetic media can (b) optical media can't be erased by magnets, magnetic media can

NAME TWO DIFFERENCES between primary storage and secondary storage.

(a) primary storage holds data/instructions that are being used currently, whereas secondary storage holds data/instructions that will be used in the future (b) primary storage is typically volatile while secondary storage in nonvolatile

NAME AND DESCRIBE each of the three components of a Central Processing Unit.

(a) registers: memory like location where data/instructions are while being used now (b) multicore: chip with multiple independent cores or "brains" (c) storage: where data and instructions reside

For each of the following, WRITE A DECLARATION STATEMENT for a variable representing this quantity. For each, you should choose an appropriate data type. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. You DON'T need to initialize the variables. Assume that intvariables and float variables take 4 bytes (32 bits) each.

(a) the number of students in CS1313 Int numberOfStudents; (b) your height in lightyears (a lightyear is the distance that light travels in a year, which is about 6 trillion miles). Int yourHeightInLightyears; Float=6 trillionMiles; (c) a spaceship's speed in inches per century, approximated to three significant figures (as- sume that the spaceship travels at 99% of the speed of light) Int spaceshipSpeedInInchesPerCentury; float=inchesPerCentury (d) the number of books on a bookshelf Int numberOfBooksOnAShelf

EXPRESS the approximate number of bytes in each of these to the nearest power of 10 (that is, as 10x for the appropriate value of x):

(a)kilobyte 10^3 or 1,000 bytes (b) megabyte 10^6 or 1,000,000 bytes (c) gigabyte 10^9 or 1,000,000,000 bytes (d) terabyte 10^12 or 1,000,000,000,000 bytes (e) petabyte 10^15 or 1,000,000,000,000,000 bytes (f) exabyte 10^18 or 1,000,000,000,000,000,000 bytes (g) zettabyte 10^21 or 1,000,000,000,000,000,000,000 bytes (h) yottabyte 10^24 or 1,000,000,000,000,000,000,000,000 bytes

WHAT IS THE OUTPUT of each of these programs? If the program has no output, mark NO OUTPUT and then EXPLAIN WHY. If the program does not compile, mark WON'T COMPILE and then EXPLAIN WHY. If the program outputs garbage, mark GARBAGE and then EXPLAIN WHY. If you are not confident of your answer, type in, compile and run the program. If you're stumped, you can try visualizing the program using: http://www.pythontutor.com/c.html#mode=edit

(b) #include <stdio.h> int main () { /* main */ printf("\n"); } /* main */ compiles. output is new line (c) #include <stdio.h> int main () { /* main */ } /* main */ No output, There is no output to be run

Write an expression that computes the average of the variables "exam1" and "exam2" (both declared and assigned values)

(exam1+exam2)/2

WHICH CHARACTER OR SEQUENCE OF CHARACTERS is the comment close de- limiter?

*/

WHICH CHARACTER OR SEQUENCE OF CHARACTERS is the comment open de- limiter?

/*

HOW does a C compiler know that the following line is a comment?

/************************/

Write a literal representing the integer value zero

0

HOW MANY different possible values can a set of 8 bits have?

0 to 255 or -128 to 172

Write a literal corresponding to the floating-point value one-and-a-half

1.5

240 is approximately 10 to what power?

10^12

210 is approximately 10 to what power?

10^3

220 is approximately 10 to what power?

10^6

230 is approximately 10 to what power?

10^9

HOW MANY different possible values can an individual bit have?

2

Based on Moore's Law, and using 2 years as the doubling period, approximately HOW MUCH FASTER will computers be in 2080 than they are today?

2^30

Based on Moore's Law, and using 2 years as the doubling period, approximately HOW MUCH FASTER will computers be in 2100 than they are today?

2^45

Write a literal corresponding to the value of the first 6 digits of PI

3.14159

WHAT IS THE OUTPUT of each of these programs, for each of the following inputs? (You do not need to show the output of the greeting nor the prompt message.) Examine the programs CAREFULLY. If you are not confident of your answer, type in, compile and run the programs. #include <stdio.h> int main () { /* main */ const float const float const float const int standard_deduction single_exemption tax_ratetax_year = 4150.0; = 2650.0; = 0.15;= 1997; float income, tax; printf("I'm going to calculateprintf(" on your %d income.\n", tax_year); printf("What was your %d income in dollars?\n", tax_year); scanf("%f", &income); tax = (income - (standard_deduction + single_exemption)) * tax_rate; printf("The %d federal income tax on $%2.2f\n", tax_year, income); printf(" was $%2.2f.\n", tax); } /* main */

30000- the 1997 federal income tax on $30000.00 was $3480.00. 40000- the 1997 federal income tax on $40000.00 was $4980.00. 100000- the 1997 federal income tax on $100000.00 was $13980.00.

WHAT IS THE OUTPUT of each of these programs, for each of the following inputs? (You do not need to show the output of the greeting nor the prompt message.) Examine the programs CAREFULLY. If you are not confident of your answer, type in, compile and run the programs. #include <stdio.h> int main () { /* main */ const float const float const float const int standard_deduction single_exemption tax_ratetax_year = 4300.0; = 2750.0; = 0.15;= 1999; float income, tax; printf("I'm going to calculateprintf(" on your %d income.\n", tax_year); printf("What was your %d income in dollars?\n", tax_year); scanf("%f", &income); tax = (income - (standard_deduction + single_exemption)) * tax_rate; printf("The %d federal income tax on $%2.2f\n", tax_year, income); printf(" was $%2.2f.\n", tax); } /* main */

30000- the 1999 federal income tax on $30000.00 was $3442.50. 40000- the 1999 federal income tax on $40000.00 was $4942.50. 100000- the 1999 federal income tax on $100000.00 was $13942.50.

On a Linux PC under the GNU gcc compiler (the compiler being used in this course), HOW MANY BITS are in a float by default? Therefore, HOW MANY DIFFERENT POSSIBLE VALUES could a float variable of the default number of bits exactly represent?

32 2^31

On a Linux PC under the GNU gcc compiler (the compiler being used in this course), HOW MANY BITS are in an int? Therefore, HOW MANY DIFFERENT POSSIBLE VALUES could an int variable represent?

32 2^32

Consider each of these numeric literal constants. COMPUTATIONALLY, does it represent an integer? EXPLAIN.

344513.000000000000000000000000000 no, decimal point 344513.000000000000000000000000001 no, non zero right of decimal point -5281023984 yes, fixed ending point 1E+15 no, it has an e

Consider each of these values. MATHEMATICALLY, does it represent an integer? EXPLAIN.

344513.000000000000000000000000000 yes, fixed ending point 344513.000000000000000000000000001 yes, fixed ending point −1281023984 yes, fixed ending point −6/3 no, no fixed ending point +9/5 no, no fixed ending point 1 · 10^18 no, no fixed ending point

WHAT CHARACTER comes at the end of every statement?

;

When a user is inputting multiple values from the keyboard, WHICH CHARACTERS may they use to separate the values being input?

;

HOW CAN YOU TELL that a declaration statement declares a variable?

= Identifier

NAME A DIFFERENCE between compilers and assemblers.

A compiler turns human-readable high-level code to machine readable. Assemblers convert human-readable assembly code to machine readable

WHAT is a declaration (also known as a declaration statement)?

A declaration is a statement tells the compiler that data exists and its properties tells the compiler- choose location in memory, nam, int/float

WHAT is a programming language?

A defined set of rules that specify the programs data and sequence of actions

WHAT is a source file?

A file of source code

WHAT IS THE DIFFERENCE between a constant and a variable? NOTE: This question is NOT about how can you tell what a declaration statement declares.

A variable's value can vary while a constant's value remains constant

WHERE in a program is that other section?

After the declaration section

WHAT is a variable?

An association among a name or address or data type

GIVE AN EXAMPLE of a character string literal constant that causes a newline to occur.

Any character string literal constant that is longer than 80 characters

The word "bit" is a contraction of WHAT PHRASE?

Binary digit

HOW CAN YOU TELL that a declaration statement declares a named constant?

By using "const" and initializing the named constant

A NEWLINE is also known as a ... ?

Carriage return

Is C case-sensitive or case-insensitive?

Case-sensitive

WHY are named constants in the body of a program GOOD?

Clarity and readability

What does Moore's Law tell us?

Company speed and capacity double every 24 moths

NAME A DIFFERENCE between compilers and interpreters.

Compilers convert human-readable high level language source code into machine-readable executable program, interpreters convert human-readable high level language code into actions that are immediately preformed

WHAT is the declaration section of a program?

Contains all the program's declarations

WHICH of the above four things does the statement below cause to be set? float y = 22.7;

Data type, value, name, and address

HOW MANY VALUES can a variable take on over the entire duration of a run?

Exactly one value

WHAT IS THE NAME of the other section of a program?

Execution section

WHY are floppy disks so expensive per MB, compared to CD-RWs and DVD-RWs?

Floppy disks have much less of a demand so fewer are manufactured which makes it difficult to have high fixed costs of running the factory

NAME A DIFFERENCE between high level languages and assembly languages.

High level languages can be used on any computer, assembly language specified to a particular computer

WHAT does a placeholder DO?

Holds place of value of variable

NAME A DIFFERENCE between assembly languages and machine languages

Humans can read assembly languages, but only machines can read machine languages

HOW MANY VALUES does a variable have at any given moment in runtime? BE VERY SPECIFIC.

Infinite values

WHAT IS THE DIFFERENCE between an input device and an output device?

Input devices transport data in a computer, output devices transfer data out of a computer

For the initialization example above, WHAT WOULD BE THE EQUIVALENT if ex- pressed as a declaration followed by an assignment?

Int x; x=3;

GIVE AN EXAMPLE of an initialization statement.

Int x=3;

WHY don't people usually program directly in assembly language?

It can't be used on all computers

WHY don't people usually program directly in machine language?

It is very tedious and error prone

In an assignment, ON WHICH SIDE OF THE SINGLE EQUALS SIGN is the name of the variable whose value is being set?

Left side

In C, WHICH CHARACTERS can be in an IDENTIFIER such as a variable name?

Letters, digits or underscore

DEFINE the word delimit.

Limit determiner

WHY are numeric literal constants in the body of a program BAD BAD BAD?

Makes it much harder to maintain and upgrade your program

WHAT IS THE DIFFERENCE between a named constant and a literal constant? NOTE: This question is NOT about how can you tell what a declaration statement declares.

Named constants have names, literal constants values are expressed literally

If I compile a C source file named my program.c on ssh.ou.edu, which has an Intel x86 processor, and I give the executable my program to you to run on a tablet computer that has an ARM processor, will you be able to run it properly? EXPLAIN.

No, the assembly languages differ so the program won't execute

WHAT is standard output?

Output to terminal screen

WHAT is an operating system?

Program that manages interactions

In an assignment, ON WHICH SIDE OF THE SINGLE EQUALS SIGN is the value that the variable is being set to?

Right side

In C, what kind of statement inputs from standard input?

Scanf statement

WHAT is a character string literal constant?

Sequence of characters deliited by " at the beginning and " at the end

WHAT is source code?

Sequence of instructions, written in human-readable programming

WHAT does an assignment statement do?

Sets contents of specific variable to specific value

WHICH of the above four things does the statement below cause to be set? int x;

Sets contents of specific variable to specific value

NAME a device that does BOTH input and output (you are not limited to the ones listed in the lecture notes, but your choice must fit the definition).

Smart phone

WHY do we use comments?

So when the program is revisited the intent and purpose is readable and can be understood by the programmer

WHAT is a program?

Specific, precise, detailed collection of data and sequence of actions on that data

How is the abbreviation of standard input PRONOUNCED?

Standard in

How is the abbreviation of standard output PRONOUNCED?

Standard out

WHAT is the name "character string literal constant" sometimes shortened to?

String literal

In the word MULTICORE, what does "core" refer to?

The independent "brains"

WHAT is compile time?

Things that occur while a program is being compiled

WHAT is runtime?

Things that occur while the program is running

WHAT is an initialization?

To declare a variable and assign a value in the same statement

WHY do computers have cache storage

To store instructions and data that have just been used or are about to be used to allow a computer to run faster

WHAT is a data type?

Type of data ether numeric or non-numeric

If a variable is declared but not initialized, and it has not yet been given a value, then WHAT VALUE does it have?

Undefined or "garbage"

WHAT is standard input?

When a user types at a keyboard

Inside a character string literal constant, HOW is a newline indicated? Give the sequence of characters.

\n

Is an assignment an ACTION or an EQUATION?

action

WHERE in a program is the declaration section?

at the beginning of program after the open block

If I compile a C source file named my program.c on ssh.ou.edu, which has an Intel x86 processor, and I give the executable my program to you to run on OU's super- computer, schooner.oscer.ou.edu, which also has an Intel x86 processor, will you be able to run it properly? EXPLAIN.

because of the similar computer architecture, if the system runs the same assembly language then theoretically it could

Given an integer variable "bridgePlayers", write a statement that increases the value of that variable by 4

bridgePlayers+=4;

Declare an int constant "MonthsInDecade" whose value is the value of the constant "MonthsInYear" (already declared) multiplies by 10

const int MonthsInDecade=MonthsInYear*10;

Given the variables "costOfBusRental" and "maxBusRiders", write an expression corresponding to the cost per rider (assuming the bus is full)

costOfBusRental/maxBusRiders

Declare a numerical variable "precise" and initialize it to the value 1.09388641

double precise=1.09388641;

Declare a variable "temperature" and initialize it to 98.6

double temperature=98.6;

Given an integer variable "drivingAge" that has already been declared, write a statement that assigns the value 17 to "drivingAge"

drivingAge=17;

Write an expression that computes the difference of the variables "endingTime" and "startingTime"

endingTime-startingTime

WHICH KEY on the keyboard will cause a new line to appear when you are typing? (NOTE: This question ISN'T asking about a newline inside a character string literal constant.)

enter

Declare a variable x, suitable for storing values like ...

float x;

Given the variables "fullAdmissionPrice" and "discountAmount" (already declared and assigned values), write an expression corresponding to the price of a discount admission.

fullAdmissionPrice-discountAmount

Given two integer variables "matricAge" and "gradAge", write a statement that gives "gradAge" a value that is 4 more than the value of "matricAge"

gradAge=matricAge+4;

NAME three ways to set the value of a variable.

input assignment initialization

WHAT does the term I/O stand for?

input/output

WHAT IS THE PLACEHOLDER for each of these data types?

int %d float %f char %c

Declare an integer variable "cardsInHand" and initialize it to 13

int cardsInHand=13;

Declare an int constant, "MonthsInYear", whose value is 12

int const MonthsInYear=12;

Declare an integer variable named "degreesCelsius"

int degressCelsius;

Declare a variable "populationChange" suitable for holding numbers like -593142 and 8930522

int populationChange;

GIVE THREE EXAMPLES of data types.

integer floating point

In C, WHICH CHARACTERS can be at the BEGINNING of an IDENTIFIER such as a variable name?

letter or underscore

WHAT FOUR THINGS does every variable have?

name address data type value

Given two integer variables "oldRecord" and "newRecord", write a statement that gives "newRecord" the same value that "oldRecord" has

newRecord=oldRecord;

Are Unix commands part of a C program?

no

YES OR NO: Are literal constants declared?

no

YES OR NO: Can a character string literal constant be more than one line long?

no

For each of the following, WRITE A DECLARATION STATEMENT for a named constant representing this quantity. For each, you should choose an appropriate data type and initialization value. The name should comply with the "favorite professor" rule, and should also be a valid C identifier. Assume that int variables and float variables take 4 bytes (32 bits) each.

normal human body temperature in degrees Fahrenheit const float body_temperature_in_degrees_fahrenheit=98.6; boiling temperature of water in degrees Celsius (at sea level on Earth, in case you're picky) const int boiling_temperature_of_water_in_degrees_celcsius=100; length of a day in hours const int day_in_hours=24;

MARK valid C variable names VALID and invalid C variable names INVALID. For invalid C variable names, EXPLAIN WHY they are invalid. (Note that valid means acceptable to the compiler, rather than good programming practice.)

number_of_students_in_CS1313 valid number of students in CS1313 invalid, can't have spaces between the words in the variable 2_to_tango valid WHAZZAT valid Huh? Invalid, variable names can't have special characters such as a question mark

WHY can C only approximate most (mathematical) real numbers?

only finitely many different values can be stored in a finite number of bits.

NAME THREE REASONS why computers use both integers and real numbers.

precision readability appropriateness

Given the variable "pricePerCase", write an expression corresponding to the price of a dozen cases

pricePerCase*12

Write an expression that computes the remainder of the variable "principal" when divided by the variable "divisor" (assuming both are type int.)

principal%divisor

WHAT KIND OF STATEMENT outputs to standard output?

printf

Given that an integer variable count has already been declared and assigned a value: Write a statement that writes the value of count to standard output

printf("%d", count);

Given that a floating-point variable "fractions" has already been declared and assigned a value: Write a statement that writes the value of "fraction" to standard output

printf("%f", fraction);

Given that an integer variable I and a floating-point variable f have been declared and given values: Write a statement in C that displays the value of I and f to standard output in the following format: I=value-of-I f=value-of-f

printf("i=%d f=%f", i,f);

Given an integer variable "profits", write a statement that increases the value of that variable by a factor of 10

profits*=10;

Given an int variable "datum" that has already been declared, write a statement that reads an integer value from standard input into this variable

scanf("%d", &datum);

When that character comes at the end of a statement, WHAT is it known as?

statement terminator

How is standard input ABBREVIATED in writing?

stdin

How is standard output ABBREVIATED in writing?

stdout

Given the variables "taxablePurchases" and "taxFreePurchases" (already declared and assigned value), write an expression corresponding to the total amount purchased

taxablePurchases+taxFreePurchases

For each of the above four things, WHO chooses it?

the name is chosen by the programming the address is chosen by the compiler the data type is chosen by the programmer the value is sometime chosen by the programmer and sometimes while the program is running

In the example programs in the lecture slides, WHAT DO WE CALL the percent sign (%)? (On ssh.ou.edu, you may have seen it as a greater than > symbol, perhaps preceded by other text.) Is it part of the C program?

unix command. no

Write an expression that computes the sum of the two variables "verbalScore" and "mathScore" (already declared and assigned values

verbalScore+mathScore

WHAT is the favorite professor rule?

when you name a variable something that is very obvious

GIVE AN EXAMPLE of an assignment statement.

x=5;

YES OR NO: Can a comment be more than one line long?

yes

YES OR NO: Can a statement be more than one line long?

yes

Some compilers on some computers automatically initialize newly declared variables to de- fault values. UNDER WHAT CIRCUMSTANCES should you explicitly initialize or assign a value to a variable, rather than letting the compiler initialize it to the default value?

you should always assign values to your variables, never assume that the compiler will initialize variable for you

WHICH CHARACTER OR SEQUENCE OF CHARACTERS is the block open delimiter?

{

WHICH CHARACTER OR SEQUENCE OF CHARACTERS is the block close delimiter?

}


Related study sets

Business Policy and Strategy Exam 1

View Set

Excretory & Immune system quizlet

View Set

Mastering Biology Chapter 7 q+a's

View Set

Conic Sections Skills 3 - vertical and horizontal lines

View Set

Cross Sectional Anatomy: The Final Battle

View Set