Final Exam prep Flashcards

1
Q

We can use the g++ compiler to read the high level code and store a translation in another file, the executable

True?
False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Words in the C++ programming language are case insensitive

True?
False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The ______ of a program language are its own precise grammar rules

a: syntax
b: semantics
c: execution
d: compilation

A

a: syntax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The ______ of a program represent the actual meaning of a segment of source code

a: indentation
b: semantics
c: syntax
d: code blocks

A

b: semantics

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The assignment operator = allots the value of the right-side expression to the left operand

True?
False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the final value of the variable b after the program is executed?
#include <cstdio></cstdio>

int main()
{
int a = 4, b = 0;
b = (a * 3) + 2;
printf(“%d”, b);
}

a: 18
b: 14
c: 0
d: 20

A

b: 14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Assume x = 2 and y = 3. What is the output of the following statement?
printf(“x=%d”, y);

a: y = 2
b: x = 2
c: x = 3
d: y = 3

A

c: x = 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

include <cstdio></cstdio>

What is the final value of the variable Pi after running the following program?

int main()
{
int age;
float myNumber;
int y = 3, z = 4;
float x = 0;
const float Pi = 3.1416;
int r = 7;
float area = 0;

Pi = Pi + 4
}

a: 0
b: None of the options listed. The program will not compile
c: 7.1416
d: 3.1416

A

b: None of the options listed. The program will not compile.

Note: the reason that the program will not compile is that 4 is not recognized by the program.

Note: declaration of a const means you cannot manipulate it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the output of the following program?
#include <cstdio></cstdio>

int main()
{
int a = , b = 3;
//b = a + 1;
//b = a * a;
b = b + a;
b = b * b;
//b = b + 2;
printf(“%d”, b);
}

a: 11
b: 0
c: 9
d: 3
Following up question: what is the purpose of %d?

A

b: 9

Answer for the following up question:
%d
prints the value of the int variable num in decimal number system
%o
prints the value of the int variable num in octal number system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

#include <cstdio></cstdio>

int main()
{
//printf(“hello world!”);
//printf(“this is a second line”);
printf”this is the a third line”);
//printf(“Programming is fun!”);
}

a: hello world!
b: this is a third line
c: Programming is fun!
d: this is a second line

A

b: this is a third line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

To use a funcion effectively, we only need to know:
_ its name
_ the type of data value (if any) it returns

True?
False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

return( printf(“%d”, ‘t’));

a: void
b: int
c: char
d: none of the options is correct

A

b: int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What would be the value assigned to x?
int x = increaseMe(increaseMe(increaseMe(3)))%7?
————————–
int increaseMe(int x)
{
int y = x + 1;
return(y);
}

a: 0
b: 1
c: 6
d: 7

A

c: 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Functions are requied to have parameters.

True?
False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What would be the value assigned to v?
int v = increaseMe(multiplyUs(6,5));
————————
int increaseMe(int x)
{
int y = x + 1;
return(y);
}

int multiplyUs(int n1, int n2)
{
return(n1/n2);
}

a: 31
b: 2
c: 1
d: 0

A

b: 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

printf(“%d”, ‘t’);

a: none of the options is correct
b: a floating point number
c: a number
d: char

A

c: a number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

float multiplyUs(float n1, float n2)
{
float result = n1 / n2;
return(‘m’);
}

void printSomethin(int number)
{
cout &laquo_space;increaseMe(number) &laquo_space;endl;
}

True?
False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

printf returns a count of how many characters it displayed

True?
False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When a return statement runs, the function immediately ends and sends back the return value

True?
False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

scanf returns a count of how many characters were assigned to a variable

True?
False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

a: if(age > 10 || userDept == 7 && userDept == 13){}

b: if(age > 10 || (userDept == 7 && userDept == 13)){}

c:if(age > 10 && userDept == 7 && userDept == 13){}

d:if(age > 10 && (userDept == 7 || userDept == 13)){}

A

d:if(age > 10 && (userDept == 7 || userDept == 13)){}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

int main()
{
int a = 1;
switch(a)
{
case 1:
cout«“One”;
case 2:
cout«“Two”;
case 3:
cout«“Three”;
default:
cout«“Default”;
}
}

a: Three
b: Default
c: One
d: None of the options listed
d: Two

A

d: None of the options listed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

a flag is a Boolean variable signaling that some condition exists in the program. When the flag is set to false it indicates the condition does not exist. When the flag is set to true it indicates that the condition does exist.

True?
False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

int main()
{
if(5 == -1)
{
cout«“M”;
}
else
{
cout«“T”;
}
}

a: M
b: The code will not compile
c: None of the options listed
d: T

A

d: T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Which logical C expression correctly determines whether x and y are greater than z?

a: (x && y > z)
b: (x > z) && (y > z)
c: (x < z) & (y < z)
d: (x > y > z)
e: none of the options listed

A

remember:
a: logically wrong

correct answer: b

26
Q

bool something(bool n)
{
if(n)
{
return(false);
}
return(something(true || n));
}

a: none of the options listed
b: true
c: false
d: the function definition is incorrect

A

c: false

27
Q

A trailing else provides code that is executed when none of the conditions in the if/else if statements are true

True?
False?

A

True

28
Q

The preferred parameter passing mechanism is called pass-by-value: It evaluates the value being passed, and copies that value to the function’s parameter

True?
False?

A

True

29
Q

Global variables should generally be avoided: they complicate maintenance and debugging, since any function in the program could be manipulating them.

True?
False

A

True

30
Q

Which of the following statements is false:

a: it is possible for multiple functions o have a local variable with the same name, but they’re all separate.
b: local variables can be accessed by other functions
c: local variables are visible within the function they are declared.
d: local variables are declared within a function

A

b: local variables can be accessed by other functions

31
Q

Like variables, the contents of an array could be any values until/unless we specifically store something. The first time we store a value in an array position we are initializing that array element

True?
False?

A

True

32
Q

The update statement is performed at the bottom of a for loop, just after each pass through the body

True?
False?

A

True

33
Q

for (int i = 1; i <= 10; i = i + 2)
{
cout«i;
}

a: 13579
b: 1357
c: 1234568910
d: 1358

A

a: 13579

34
Q

What loops need a semi colon after?

a: do
b: while
c: all of the options listed
d: for

A

a: do

35
Q

What is the output of the following program:

int main()
{
int myArray[4] = {77, 33, 44, 8};

    for(int i=0; i < 4; ++i)
    {
            cout << myArray[i];
    } }

a: 7348
b: None of the options listed
c: 8443377
d: 7733448

A

d: 7733448

36
Q

In nested loops, the outer loop runs to completion first (likely multiple times) before the inner loop is executed

True?
False?

A

False

37
Q

For an array of size N, the positions are numbered 0…N.

True?
False?

A

False

reason: 0 to N-1

38
Q

The following code will produce an infinite loop:

int main()
{
int i = 10;
while(i<100)
{
cout &laquo_space;i &laquo_space;endl;
}
}

True?
False?

A

True

39
Q

What loops are guaranteed to execute at least once?

a: while
b: none of the options listed
c: d
d: for

A

c: do

40
Q

An array is organized into positions, each acting as a storage spot for one item

True?
False?

A

True

41
Q

When we define a struct we are actually defining a new data type: a structure made up of a variety of components, or fields, each given heir own name

True?
False?

A

True

42
Q

When passing arrays as parameters to functions, the function can by default change the content of the array.

True?
False?

A

True

43
Q

When functions include optional parameters, you must also consider the ambiguity of possible combinations of passed parameters.

T or F

A

True

44
Q

In terms of order of parameter assignment, the parameters passed by the caller are assigned to the formal parameters in right-to-left order. Then any remaining parameters use their default values.

T or F

A

False

45
Q

include <iostream></iostream>

What is the output of the following program:

using namespace std;

void swap(float &x, float &y);

int main()
{

    const int Size = 5;
    float one[Size] = {1, 3, 5, 7, 9};

    swap(one[0],one[Size-1]);
    swap(one[0],one[2]);

    for(int i=0; i < Size; ++i)
    {
            cout << one[i];
    }

}

void swap(float &x, float &y)
{
float temp = x;
x = y;
y = temp;
}

a: 53971
b: 53179
c: 13579
d: 97531
e: None of the options listed

A

a: 53971

46
Q

include <iostream></iostream>

What is the output of the following program:

using namespace std;

struct something
{
int x, y;
};

int main()
{
something a, b, c;
a.x = 1;
a.y = 3;
b.x = ++a.x;
c.y = 9;
cout &laquo_space;c.y - b.x;
}

a: 9
b: 0
c: 1
d: none of the options listed
e: 7

A

e: 7

47
Q

Binary search is more efficient than linear search

T or F

A

True

48
Q

Structs allow us to group elements of a specific data type into a single logical entity, then refer to them by position.

T or F

A

False

49
Q

include <iostream></iostream>

What is the output of the following program:

using namespace std;

int foo(int arr[], int size);

int main()
{

    int goo[5] = {9,7,5,3,1};
    cout << foo(goo,5);

}

int foo(int arr[], int size)
{
int total = 0;
for (int p=0; p<size; p=p+2)
{
total = total + arr[p];
}
return(total);
}

a: 25
b: None of the options listed
c: 0
d: 15
e: 9

A

d: 9

50
Q

Binary search works on a sorted or unsorted array

T or F

A

False

51
Q

When we define a struct we are actually defining a new data type: a structure made up of a variety of components, or fields, each given their own name.

T or F

A

True

52
Q

Extra syntax can be added to the definition of a parameter to allow a function to alter its actual value. What is that syntax?

a: none of the options listed
b: &
c: %
d: =

A

b: &

53
Q

The update statement is performed at the bottom of a for loop, just after
each pass through the body.

T or F

A

True

54
Q

What is the output of the following program:

int main()
{
int myArray[4] = {77, 33, 44, 8};

    for(int i=3; i >=0 4; --i)
    {
            cout << i;
    } }

a: 8443377
b: 0123
c: 3210
d: 7733448

A

a: 8443377

55
Q

What value will be returned from evaluating something(4)?

int something(int n)
{
if(n==0)
{
return(0);
}
return(n * something(n-1));
}

a: 4
b: 24
c: 12
d: 0

A

d: 0

56
Q

We can use & to look up the memory address of constants, variables, and parameters.

T or F

A

True

57
Q

We can use a pointer to access the contents of an address in memory. This is is called dereferencing.

T or F

A

True

58
Q

include <iostream></iostream>

What is the output of the following program:

using namespace std;

int main()
{
int *x, *y, X;
x = &X;
y = x;
*x = 7;
*y = 13;
cout &laquo_space;X;
}

a: 7
b: 0
c: none of the options listed
d: 13

A

d: 13

59
Q

We declare pointer variables by adding & to the data type

T or F

A

False

60
Q

include <iostream></iostream>

What is the output of the following program:

using namespace std;

int main()
{
const int size =2;
int *p1, *p2;
int arr[size];

    p1 = &arr[0];
    p2 = arr;
    if( p1 == p2)
    {
      cout << 1;
    }
    cout << 7;  }

a: 7
b: none of the options listed
c: 1
d: 17

A

d: 17