comp 1200

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which includes a header file in the same directory as the file including the header?

#include "myheader.h"

Which expression fails to compute the area of a triangle having base b and height h (area is one-half base time height)?

(1 / 2) * b * h

Which generates a random integer in the range 13..19?

(rand() % (19 - 13 + 1)) + 13

Dice have 6 sides, with values 1, 2, 3, 4, 5, and 6. Which expression randomly rolls one dice, directly yielding one of those values?

(rand() % 6) + 1

Which expression evaluates to 3.5? int x = 7;int y = 1;

(x / 2.0)

What are the possible values for ((rand() % 9) + -4)?

-4...4

What is the ending value of y? int x; int y; x = 6; y = (1 / 2) * (x + 5);

0

What are the possible values for rand() % 6?

0...5

What possible values can x % 10 evaluate to? (x is an integer).

0..9

What is the ending value of y? int x; int y; x = 2; y = ((x + 1) / 5) + (x / 2) ;

1

What is the final value of A in the set of statements below? int A = 10; int B = A; B = 20;

10

What is the output? int FindSqr(int a) {int t;t = a * a;return a;}int main(void) {int square;square = FindSqr(10);printf("%d", square);return 0;}

10

What is y after executing the statements? x = 4;y = x + 1;x = 3;y = y * 2;

10

What is the ending value of x? int y = 6;x = (1 / 2) * y + 8;

11

What is y after executing the statements? x = 5; y = x + 1; y = y * 2;

12

Given the code snippet below, what would the final value of the variable answer be? int add_two(int x, int y){return x + y;}int return_answer(int x, int y){return add_two(x,y);}int main(void){int a = 5, b = 10;answer = return_result(a, b);}

15

What is the output? int Calc(int num1, int num2) {return 1 + num1 + num2;}int main(void) {int x;x = Calc(4, 5);printf("%d", Calc(x, 5));return 0;}

16

How many parameters does the function below have? void some_function(int x, int y){int answer = x + y;printf("The answer is: %d\n", answer);}

2

What is the ending value of x? x = 160 / 20 / 4;

2

What is the value of x? int y = 9; int z = 3; double x; x = (y / (z + 1.0));

2.25

What is the value of the variable answer if you executed the code below? int x = 20;double y = 2.5;int answer = x + y;

22

What is the output? #include <stdio.h>const double LB_PER_KG = 2.2;double KgsToLbs(double kilograms) {double pounds;pounds = kilograms * LB_PER_KG;return pounds;}int main(void) {double pounds;pounds = KgsToLbs(10);printf("%lf", pounds);return 0;}

22.0

What is the ending value of cost? int numApples = 3;double cost;cost = 1.2 * numApples;

3.6

What is the ending value of w? int w; int y; y = 34; w = y % 5;

4

What is the final value of the variable var3 in the code snippet below? int var1 = 3; int var2 = 2; int var3 = var1 + var2; var1 = 5; var2 = 6; var2 = 7;

5

double MyFct(double a, double b) {return (a + b) / 2.0;}int main(void) {double x = 3.0;double y = 5.0;double z = 8.0;double t;t = MyFct(x, y);t = MyFct(t, z);printf("%lf\n", t);return 0;}

6.0

What is the ending value of z? x = 0; y = 3; z = pow(x + 2, y);

8

What is the ending value of y? sqrt(u) returns the square root of u. pow(u, v) returns u raised to the power of v. x = 9.0; y = 4.0; y = pow(sqrt(x), sqrt(y));

9.0

What does the compiler do upon reaching this variable declaration? int x;

Allocates a memory location for x

Which is not true?

Attempting to predict a bug's source is bad practice

Given the code snippet below, what would the final value of the variable answer be? void add_two(int x, int y){int result = x + y;}int main(void){int a = 5, b = 10;answer = add_two(a, b);}

Error. Function add_two doesn't return anything.

What is the final value of A in the set of statements below? A = 10; int B = A; B = 20;

Error: A was never declared

The following program results in a compiler error. Why? int FindMin(int a, int b) {int min;if (a < b) {min = a;} else {min = b;}return min;}int main(void) {int x;int y;scanf("%d", &x);scanf("%d", &y);min = FindMin(x,y);printf("The smaller number is: %d\n", min);return 0;}

FindMin() should be defined after main(), not before.

Which is true?

Format specifiers for scanf() and printf() are identical

What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */rate = 0.5; */

Generate an error.

For which quantity is a double the best type?

Height of a building

What does this code output? printf("I "); printf("want pie.\n");

I want pie.

What will a compiler do for the following three lines of code? // x = 2; // width // y = 0.5 // z = x * y;Total area

Ignore all three lines

What will a compiler do for the following three lines of code? // x = 2; // width// y = 0.5// z = x * y; Total area

Ignore all three lines

Which line of the function has an error? int ComputeSumOfSquares(int num1, int num2) {int sum; // Line 1sum = (num1 * num1) + (num2 * num2); // Line 2return; // Line 3}

Line 3

What is the output? void IsEven(int num) {int even;if (num % 2 == 0) {even = 1;}else {even = 0;}}int main(void) {IsEven(7);printf("%d", even);return 0;}

No output: A compiler error occurs due to unknown variable even

Given the code snippet below, what would print on the console? int add_two(int x, int y){int answer = x + y;return answer;}int main(void){int a = 10, b = 20;add_two(a, b);printf("Answer is: %d\n", answer); }

Nothing would print because the variable answer is not in the scope of the main function.

What is read into string myString for input "One-hit wonder"? scanf("%s", myString);

One-hit

Which is true for comments?

The compiler does not generate machine code for comments.

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling?

The first error only

What is the purpose of a variable?

To hold a value

Which is a good testing tactic?

Use printf() statements to inspect variable values

Which is not true?

Variables must be declared before being assigned a value or read

What "exactly" would be printed on the console given the printf statement below? double X = 2, Y = 2; printf( "X is %.2lf and Y is %.2lf\n", X, Y);

X is 2.00 and Y is 2.00

Given only int variables a and b, which is a valid expression?

a + -2

Which declaration assigns a variable with 5 such that the value can not be later changed?

const int NUM_ITEMS = 5;

Which is a valid definition for a function that passes two integers (a, b) as arguments, and returns an integer?

int MyFunction(int a, int b)

Which is correct?

int changeAmt = -321;

Which is correct?

int main(void) {int pkgHeight;int pkgLength;int pkgWidth;int pkgVol;pkgVol = pkgHeight * pkgLength * pkgWidth;}

What does the compiler do upon reaching this variable declaration?

int x;

Which of the following is a correct way to create a variable that can store a whole number only?

int x;

For the following function, which is a valid function call? Assume maxValue is an integer. int Max(int x, int y) {if (x > y){return x;}else {return y;}}

maxValue = Max(15, Max(35, 25));

myChar is a character variable and is the only declared variable. Which assignment is valid?

myChar = 't';

Does the function below return anything? void some_function(int x, int y){int answer = x + y;printf("The answer is: %d\n", answer);}

no

Which XXX tests the input value 4 using a print statement (without using assert)? int SquareNum(int origNum) {return origNum * origNum;}int main(void) {printf("Testing started\n");XXX;printf("Testing completed\n");return 0;}

printf("4, expecting 16, got: %d\n", SquareNum(4))

Which XXX results in the output "I feed my 3 cats"? #include <stdio.h>int main(void) {int numCats = 3;char choreStatement[] = "feed";XXX}

printf("I %s my %d cats", choreStatement, numCats);

Choose the statement(s) that generate(s) this output: I wish you were here

printf("I wish\n"); printf("you were here");

Which of the following correctly uses the printf function to print EXACTLY the text below this question, assuming that X and Y were doubles and that X=2.5 and Y=3.5567? X is 2.50 and Y is 3.55 <-- print this statement to terminal

printf("X is %.2lf and Y is %.2lf", X, Y);

Which expression is most appropriate for randomly choosing a day of the week?

rand() % 7;

Given char x, which reads an input character into x?

scanf("%c", &x);

Which of the following correctly uses the scanf function to save a value into the variable some_var, if some_var were an integer data type?

scanf("%d", &some_var);

Which of the following correctly uses the scanf function to save a value into the variable some_var, if some_var were a double data type?

scanf("%lf", &some_var);

Which expression doubles x?

x *= 2;

Which statement is incrementing the integer x, where y is also an integer?

x = x + 1;

For an integer constant x, which statement will yield a compiler error?

x = y + 1;

Given char x and char z, which assigns x with the character value held in z?

x = z;

Which XXX is valid for the following code? int CalcSum(int a, int b) {return a + b;}int main() {int y;XXXreturn 0;}

y = CalcSum(4, 5);

A program should compute two times x. Which statement has a logic error?

y = x * x;


Kaugnay na mga set ng pag-aaral

Chapter 7, "The Normal Probability Distribution,"

View Set

Chapter 7: The Behavior of Proteins: Enzymes, Mechanisms, and Control

View Set

MODULE 1: Objectives and Elements of Supply Chain Management

View Set

MGMT 464 Honoree Exam 2 this one

View Set

Assessment and Management of Patients with Hepatic Disorders CIRRHORIS PREP U STUDY GUIDE

View Set