CPSC 1010 Exam 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the total number of characters in this array? char word1[] = {"CS for all"};

11

What will be printed after the following code snippet executes? int x = 3, y = 8, result; if (x > y) result = y + ++x; else result = y + x++; printf("%d", result);

11

What is the output of the following code snippet? for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); }

* ** *** **** *****

What is the output of the following code snippet? for (i = 1; i <= 5; i++) { for (j = 1; j <= 4; j++) { printf("*"); } printf("\n"); }

**** **** **** ****

After the following code executes, what would be the value of result that will be printed by the printf() statement? #include <stdio.h> int main(void) { int a = 100, b = 2, c = 25, d = 3, e = 1; int result; result = -a + d; printf("%d", result);

-97

After the following code executes, what would be the value of mod? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; y = 3; quotient = x / y; mod = x % y;

1

After the following code executes, what would be the value of product? int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; y = 5; product = 2 * y++;

10

The logic and the approach or steps taken to solve the problem.

algorithm

This refers to the approach or steps taken to solve the problem, to show the logic for the program before you start coding.

algorithm

When you are getting ready to write a program, what is the first step? Create a(n) ____________________________.

algorithm

The second sub-step when compiling where the programming language instructions are broken down into assembly language instructions first (.s file) and then converts each assembly language instruction into binary code, or object code (.o file).

assembler

What type of language is the following? ADD Bx Ax

assembly

These are low-level types of instructions that, starting in the early 1950s, allowed the programmer to use a somewhat more English-like way of writing instructions by using abbreviations, or mnemonic codes, to refer to the bit-patterns.

assembly language

A program used to translate the statements from the higher-level language into a form that the computer understands.

compiler

This is the process of analyzing & translating the program from a high-level programming language (such as C) to a form the computer can understand (machine language); creates an executable.

compiling

The syntax of the for loop is: for (initializationStatement; testExpression; updateStatement). Which one of those 3 items in the for loop is the first thing that is done and only ever happens once?

initializationStatement

These are the instructions that are defined on a processor. Different processors have different ones of these defined on them (within the circuitry of the processor).

instruction set

Declare an array called numArray2 that can contain 9 integers initializing each one to 0.

int numArray2[9] = {0};

Assembly language is also known as _______________________ language

low-level

What is the Unix/Linux command for showing the list of files and directories one directory below where you are currently located?

ls ..

There are different types of instructions and different types of languages. Which type of language consists of primitive instructions from the instruction set?

machine

These are the (low-level) types of instructions that the computer (processor) understands. They are not human readable; they are machine dependent - only worked on the machine that it was developed for (not portable).

machine language

Program execution begins where in a program? (__________________{})

main

Let's say you are currently logged in to /home/<your_userid>/Fall23/Classes/CPSC/lecture/ directory and that you have a file in that location called prog.c. You want to change the name of the program from prog.c to prog1.c and only want the one copy of the file (that will be called prog1.c). What Unix/Linux command will allow you to achieve this with just one command?

mv prog.c prog1.c

Assign the value 5 to the 2nd element in numArray1.

numArray1[1] = 5;

Write code to assign the value 12 to the 3rd element in the array numArray1.

numArray1[2] = 12;

Assign to the 7th element in numArray2 the value of the 3rd element in numArray1.

numArray2[6] = numArray1[2];

These are the programs that control the entire operation of a computer system (such as I/O, system resources, execution of programs, etc).

operating system

C is a __________________________________________ programming language (like Ada, BASIC, C++, C#, COBOL, Fortran, Java, Pascal, Perl, Python, Visual Basic).

procedural

This is a type of programming language that contains a series of computational steps to be carried out; procedures / routines / functions may be called at any point in the program, including by other functions or itself.

procedural

What type of language is the following? sum = num1 + num2;

programming

These are logical errors, e.g. using a variable that hasn't been declared yet.

semantic

Logical errors, e.g. using a variable that hasn't been declared yet

semantic errors

Your C code that you type up in a file for a program, for example prog2.c, is called what type of code?

source code

After the following code executes, what would be the value of product? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; y = 5; product = 2 * ++y;

12

After the following code executes, what would be the value of sum? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; sum = x + y;

12

After the following code executes, what would be the value of result that will be printed by the printf() statement? #include <stdio.h> int main(void) { int a = 100, b = 2, c = 25, d = 3, e = 1; int result; result = a - ( (b + c) * d ); printf("%d", result);

19

After the following code executes, what would be the value of product? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; sum = x + y; quotient = x / y; diff = x - y; product = x * y;

20

Use an online ASCII table for this question: What would print to the screen with this code? int array3[5] = {1, 2, 3}; int i; for (i = 1; i < 5; i++) printf("%d", array3[i]); // no space after each value

2300

After the following code executes, what would be the value of c that will be printed by the printf() statement? #include <stdio.h> int main(void) { int a = 100, b = 2, c = 25, d = 3, e = 1; int result; c += b; printf("%d", c);

27

After the following code executes, what would be the value of quotient? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; y = 3; quotient = x / y;

3

After the following code executes, what would be the value of y after the last line of code that is shown? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; y = 5; y -= 1;

4

Consider the following program: #include <stdio.h> int main() { fprintf(stderr, "I love programming!"); return 0; } After the code compiles, let's say the user executes the following command: ./a.out > output.txt What will be printed to the screen? A) the following will print to the screen: I love programming! B) the following will print to the screen: output.txt C) nothing will print to the screen

A

Consider the small program below. It contains several errors that would need to be fixed before it will successfully compile. On which line number is the first error in the program? 1 #include <stdio.h> 2 3 int main() { 4 int a = 2 b = 8, c = -3, result; 5 result = 6 + b a * c; 6 printf("result is: %d\n', result) 7 8 result = a - b + c * 5); 9 printf"result is: %d\n", result); 10 11 return 0: 12 }

4

On our system, what would print from the following printf statement? printf("%d", (int)sizeof(int));

4

Use an online ASCII table for this question: What would print to the screen with this code? int array3[5] = {'1', '2', '3'}; int i; for (i = 0; i < 3; i++) printf("%d ", array3[i]); // notice the space after each value

49 50 51

After the following code executes, what would be the value of quotient? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; sum = x + y; quotient = x / y;

5

Suppose string str1 is initially Hello and str2 is Hi What value is returned by calling strlen(str1)?

5

What is the value of p after the statements below? int n, s=0, p=0; for (n=1; n<4; n++) { p += 2 * n - s; s = p + 1; }

5

After the following code executes, what would be the value of quotient2 that will be printed by the printf() statement? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; float quotient2; y = 5; y -= 3; quotient2 = (float)x / y; printf("%.1f", quotient2);

5.0

After the following code executes, what would be the value of quotient2 that will be printed by the printf() statement? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; float quotient2; y = 5; y -= 3; quotient2 = (float)x / y; printf("%f", quotient2);

5.000000

After the following code executes, what would be the value of quotient2 that will be printed by the printf() statement? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; float quotient2; y = 5; y -= 3; quotient2 = x / y; printf("%f", quotient2);

5.000000

Given the following array declaration, what is maxScores[3]? int maxScores[4] = {20, 20, 100, 50};

50

What is the total number of characters in this array? char word1[] = {'a', 'l', 'l', ' ', 'i', 'n'};

6

After the following code executes, what would be the value of diff? #include <stdio.h> int main(void) { int x = 10, y = 2; int sum = 0, product = 0, diff = 0, quotient = 0, mod = 0; sum = x + y; quotient = x / y; diff = x - y;

8

What is the highest valid indices of an array of size 9? (0, 1, 2.... ____?)

8

A program's statements execute: A) Sequentially B) All at once

A

Consider the following code snippet. Which statement will be printed? int a = 25, b = 4; if (a = b) printf ("Values of both variables are equal. \n"); else printf ("Values of both variables are different. \n"); A) Values of both variables are equal. B) Values of both variables are different.

A

Consider the following program: #include <stdio.h> int main() { printf("I love programming!"); return 0; } After the code compiles, let's say the user executes the following command: ./a.out > output.txt What will be printed to the screen? A) the following will print to the screen: I love programming! B) the following will print to the screen: output.txt C) nothing will print to the screen

A

If grades is an array of 10 floats, what is the type of grades[0]? A) float B) array of floats C) boolean D) int

A

When you compile your program, what are the different phases of compilation, in order? A) preprocessor, assembler, linker, loader B) preprocessor, assembler, loader, linker C) assembler, preprocessor, linker, loader D) assembler, preprocessor, loader, linker

A

Which of the following enables you to split the flow of your program into 2 or more pathways which are usually the resultof conditional statements such as if or switch statements? A) Branching B) Looping

A

Which of the following would produce a compile error? A) float grades[]; B) float grades[] = {95.0, 90.0, 80.0, 85.0, 75.0}; C) float grades[] = {[0] = 95.0, [10] = 90.0}; D) float grades[7];

A

This person from the 1800s is considered to have written the first "computer program". (From the 1800s? How can that be?) There is a computer programming language named after this person.

Ada Lovelace

An output statement from a printf( ) sends values to a: A) File B) Screen

B

Consider the following code snippet. Which statement will be printed? int a = 0, b = 0; if (a = b) printf ("Values of both variables are equal. \n"); else printf ("Values of both variables are different. \n"); A) Values of both variables are equal. B) Values of both variables are different.

B

If grades is an array of 10 floats, what is the type of grades? A) float B) array of floats C) boolean D) int

B

If the results of compiling your program look like the following: prog1.c: In function 'main': prog1.c:14:2: error: expected ';' before 'return' return 0; ^ The error in your program... A) must be on line 14 B) could be on line 14 or an earlier line before line 14 C) could be on line 14 or a line after line 14

B

What makes a do-while loop different than the other 2 types of loops? A) The code in the body may not execute at all. B) The code in the body always executes at least one time. C) The code in the body always executes at least two times.

B

Which of the following enables you to develop concise programs containing repetitive processes that could otherwiserequire many lines of code? A) Branching B) Looping

B

Suppose string str1 is initially Hello and str2 is Hi After the following code, what will str2 be? (Assume the lengths of the strings are large enough for all of the following code).

Bye Hi

Consider the following program: #include <stdio.h> int main() { fprintf(stderr, "I love programming!"); fprintf(stdout, "This is my favorite class."); return 0; } After the code compiles, let's say the user executes the following command: ./a.out > output.txt What will be printed to the file called output.txt ? A) both lines: I Love programming! This is my favorite class. B) only the first line: I love programming! C) only the second line: This is my favorite class D) nothing will print to the file called output.txt

C

If ages is an array of 10 ints, what is the type of ages[3] < 21? A) int B) array of ints C) boolean D) float

C

When was C developed? A) late 1950s to early 1960s B) mid-1960s C) late 1960s to early 1970s D) mid 1970s

C

Which of the following allocates an array of 10 floats named grades? A) float array[10] grades; B) float [10] grades; C) float grades[10]; D) float array grades 10;

C

Which of the following s an array called numArray1 that can contain 9 integers? A. int array[9] numArray1; B. int [9] numArray1; C. int numArray1[9]; D. int array numArray1 9;

C

This is the "brains" of the computer that carries out the retrieve, decode, execute, write-back results cycle, which is measured in GHz.

CPU

What are the 3 types of loops in C? A) for, infinite, nested B) for, do-while, nested C) for, while, nested D) for, while, do-while

D

Answer T for true or F for false: A compiler warning by default will prevent an executable from being created.

F

Answer T for true or F for false: A compiler's default settings cause all warnings to be reported during compilation.

F

Answer T for true or F for false: Generally, a programmer should ignore warnings.

F

Answer T for true or F for false: If a compiler says that an error exists on line 90, the actual error may be on line 91, 92, or 93.

F

Answer T for true or F for false: When a compiler says that an error exists on line 5, that line must have an error.

F

Let's say you have a C-string called userName already declared this way: char firstName[15]; You could assign to firstName the value of Sarah this way: firstName = "Sarah"; True or False? (Answer T for true, F for false)

F

Evaluate the following to true (1) or false (0): !(1 || !(0 && 1))

False

Who created the first compiler? (She also coined the phrase "debugging")

Grace Hopper

Suppose string str1 is initially Hello and str2 is Hi After the following code, what will str1 be? (Assume the lengths of the strings are large enough for all of the following code). strcpy(str1, str2); strcpy(str2, " Bye "); strcat(str2, str1);

Hi

Which of the following are valid ways of declaring a C-string called myString that contains 25 characters? 1) char myString[ ]; 2) char myString[25]; 3) int myString[25]; 4) char [25] myString; Enter response in order 1-5 using Y for yes/valid, N for no/not valid. Example: NYYN

NYNN

Which of the following are valid ways of declaring a C-string called word1 that contains the word Hello! 1) int word1[ ] = "Hello!"; 2) char word1[ ] = "Hello!"; 3) char word1[6] = "Hello!"; 4) char word1[7] = "Hello!"; Enter response in order 1-5 using Y for yes/valid, N for no/not valid. Example: NYYN

NYNY

Which of the following are valid variable declarations? 1) int 1num; 2) int _1num; 3) int num1; 4) Bool true; 5) int Num_1; Enter response in order 1-5 using Y for yes/valid, N for no/not valid. Example: NNYNY

NYYNY

This is the part of the computer that allows the computer to "think". The items that are currently being processed are held here in this temporary storage, also called main memory. It is measured in GB.

RAM

Answer T for true or F for false: If a compiler generates a specific message like "missing semicolon", then a semicolon may be missing somewhere, though maybe from an earlier line than what it's showing.

T

What is another way of writing: a += 5;

a = a + 5;

This is the basis for many modern operating systems. It was developed at Bell Labs in 1969. One of the driving philosophies of this operating system was that everything consists of small modular units that do one thing well and when combined, can do more powerful things.

Unix

Is this a valid array declaration? int array2[] = {1, 2, 3, 4, 5}; (Answer Y for yes, N for no)

Y

Language-specific omissions/errors, e.g., missing a semi-colon where one is required.

syntax error

The syntax of the for loop is: for (initializationStatement; testExpression; updateStatement). Which one of those 3 items in the for loop is what determines whether the code in the for loop body will execute?

testExpression


संबंधित स्टडी सेट्स

Hinkle 58 Assessment and Management of Patients With Breast Disorders

View Set

Science - Work, Power, and Energy

View Set

BIOLOGY CHAPTER 14 LEARNING CURVE QUESTIONS

View Set

EXAM 1 COMMUNICATION AND GROUP DYNAMICS NOW EXAM 4

View Set

International Business Law Chapter 15

View Set

Varacolis Mental Health Chapter 34

View Set