Midterm Flashcards

1
Q
  1. Arrays in C++ must have a fixed size that is determined at the time of declaration.
  2. Elements in an array are stored in contiguous memory locations.
  3. It is possible to have arrays with a variable size that can be changed at runtime.

The Lie is #?

A

3

arrays must have a fixed size that is determined at the time of declaration and can not be changed later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. The index of the first element in an array is always zero (0).
  2. The size of an array is stored as a member variable of the array.
  3. It is possible to initialize an array in C++ using a loop.

The lie is #?

A

2

Array doesn’t have any member variable to store the size of an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. It is possible to pass an entire array as an argument to a function.
  2. The elements of an array in C++ are stored in the order they are declared.
  3. It is possible to have a multidimensional array using only one pair of square brackets.

The lie is #?

A

3

To have a multidimensional array, multiple pairs of square brackets are required, one for each dimension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. It is not possible to copy the values of one array to another array using the assignment operator.
  2. The for-each loop can be used to iterate through the elements of an array.
  3. C++ arrays have a built-in method to sort their elements in ascending or descending order.

The lie is #?

A

1

It is possible to copy the values of one array to another array using the assignment operator in C++ using (=).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. It is possible to create an array of pointers in C++.
  2. A single-dimensional array can be passed to a function as a reference.
  3. It is not possible to use the relational operators such as <, >, <=, >= to compare two arrays.

The lie is #?

A

3

it is possible to use the relational operators such as <, >, <=, >= to compare two arrays, as long as the arrays are of the same type and size.

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

What is a type of array that can store multiple arrays with the same data type?

A

Multidimensional

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

What is Function?

A

Subprogram that performs task.

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

What is function overloading in C++?

A

Using same function name multiple times.

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

What are function parameters in C++?

A

Using same function name multiple times.

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

What are function parameters in C++?

A

Information passed to a function.

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

What is function return type?

A

Data type of returned value.

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

Can a function return multiple values?

A

No, only one value returned

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

What are user-defined function types?

A

Custom data types.

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

A function that calls itself

A

Recursion

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

Can a function be declared inside main?

A

Yes

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

What is the purpose of function overloading in C++?

A

To use same name, different tasks.

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

What is a default argument in C++?

A

Predetermined value for parameter.

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

T/F Function overloading allows multiple functions with same name.

A

True

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

T/F Default arguments are mandatory in C++.

A

False

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

T/F Function prototypes are only used for functions with no return type.

A

False

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

T/F Inline functions can only be declared inside main.

A

False

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

T/F Reference parameters are alternative to values.

A

False

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

What is the purpose of function parameters?

A

To pass information to a function.

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

What is the purpose of default arguments?

A

To provide predetermined values for parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the purpose of function return type?
To specify data type of returned value.
26
What is the purpose of user-defined function types in C++?
To create custom data type for functions.
27
What is the purpose of function overloading in C++?
To use same function name for different tasks.
28
The code "int max (int num1, int num2);" is a Function _____
Declaration
29
What are the mandatory parts of a function declaration?
Return type and function name
30
A type of variable inside a function
Local
31
In C++, which of the following is TRUE? All of the mentioned Function can have no argument but no return value Functions can have no argument and no value Function can have no argument but return value
All of the mentioned
32
A function can be called from another function using its __
name
33
Which of the following is NOT included in a function declaration? Colon : function_name semicolon ; parameter list
colon :
34
Which of the following is NOT a proper function prototype (definition)? func(int x) void funct(); int secondfunct (char x, char y) ; char letter();
func(int x)
35
Where does the “return statement” return the execution of the program?
main function
36
#include using namespace std; void f1() { cout <<1;} int main() { f1(); goto x; cout << "hello"; x: cout << "hi"; return 0;} What is the output of the following code?
Error
37
Which of the following doesn’t return a value? void myPassingGrade(int x, int y) double myPassingGrade (double p, double q) int myPassingGrade (double p, double q, double r) int myPassingGrade(int z)
void myPassingGrade(int x, int y)
38
Which value will it take when both user and default values are given?
user value
39
What is the return value of the following function: double myRewards(double x, double y)?
double
40
In order to return a value from a function you must use:
return
41
What is the output of the program? #include using namespace std; int fun(int=0, int = 0); int main() { cout << fun(5); return 0; } int fun(int x, int y) { return (x+y); }
5
42
It refers to merging of two strings
concatenation
43
Compares the C string str1 to the C string str2
strmcp()
44
Returns true if the provided character expression is a printing character other than whitespace, a digit, or a letter; otherwise returns false.
ispunct()????
45
Returns true if character expression is either a letter or a digit otherwise false
isalnum()
46
Returns true provided character expression is a lowercase letter otherwise it returns false
islower()
47
Returns true provided character expression is a whitespace character, such as the blank or newline character, otherwise, returns false
isspace()
48
What is the error in the following program? #include #include using namespace std; int main () { char key[] = "apple"; char buffer[80]; do { cout << "Guess my favorite fruit? "; cin.getline(buffer,80); } while (strcmp (key,buffer) != 0); cout << "Correct answer!" return 0; }
Missing semicolon
49
Which of the following function allows you to read on a character? get() put() strcpy() getline()
get()
50
Check the following program #include #include using namespace std; int main () { int i; char str[]="c3po...??"; i=0; while (isalnum(str[i])) i++; cout << "The first " << i << " characters are alphanumeric.\n"; return 0; } What is the value of i?
4
51
Returns true if character expression is a letter of the alphabet otherwise false
isalpha()
52
Which of the following operator can be used also in strings? Group of answer choices + @ -
+
53
What is the header file for the string class?
#include
54
The append operator is denoted by:
- +=
55
What is the output of the following program? #include #include using namespace std; int main () { string str1 = "Hello"; int len = str1.size(); cout << len << endl; return 0; }
5
56
What is the output of the following program? #include #include using namespace std; int main() { char str1[] = "C++"; string str = "Programming"; int len1 = strlen(str1); int len2 = str.length(); cout << len1+len2; return 0; }
14
57
The sequence of contiguous characters in memory is called _________
Character Strings
58
What is the output of the following program? #include #include using namespace std; int main () { string myString = "Hello"; cout << myString[0]; return 0; }
H
59
Which of the following functions gets the length of a string?
length()
60
What is the output of the following program? #include //faggot #include using namespace std; int main () { string str3(5, '#'); cout << str3; return 0;
#####
61
An operation where in data is added to the existing data of file
Append
62
What is the correct syntax for declaring a file pointer?
FILE *fp;
63
What does the following code do? while( (ch = getchar()) != '\n') { putc(ch, fp); }
Gets a character, put it into a file pointer until an enter is pressed
64
It represents a sequence of bytes on the disk where a group of related data is stored.
File
65
Creates a new file or open an existing file
fopen()
66
When will the cin can start processing of input?
After pressing return key
67
By default, all the files in C++ are opened in _________ mode.
Text
68
What is the return type open() method?
int
69
A C++ library that allows working with files
fstream
70
Which of the following header file is required for creating and reading files? stream fstream ifstream ofstream
fstream
71
Which of the following has a correct C++ class definition? class Student {}; class Student; class Student () class Student {}:
class Student {};
72
What is the difference between struct and class in C++? Group of answer choices All of the given Members of a class are private by default and members of struct are public by default. All members of a structure are public and structures don't have constructors and destructors All members of a structure are public and structures don't have virtual functions
Members of a class are private by default and members of struct are public by default.
73
What operator is used to access a data member or a member function? == operator & operator dot (.) operator + operator
dot (.) operator
74
Which of the following best defines a class? Blueprint of an object Scope of an object Parent of an object Instance of an object
Blueprint of an object
75
Which concept of OOP is false for C++? A class must have member functions At least one object should be declared in code Code must contain at least one class Code can be written without using classes
Code must contain at least one class
76
What symbol is used to define a function outside of the class? <> & :: :
::
77
If a class is named Car and you will create an object named SportsCar, what would be the statement? Car; Car (SportsCar); Car SportsCar; SportsCar Car;
Car SportsCar;
78
An object is a _________________ of a class
an instance
79
If a class is named Fruits and you will create an object named Apple, what would be the statement? Apple@Fruits; Apple Fruits; Fruits Apple; Fruits(Apple);
Fruits Apple;