In: Computer Science
Question 11
mystring.length() or mystring.size() will return the length of the string in mystring.
Question 11 options:
True | |
False |
Question 12
To access an element of an array of structures you use the ________ operator.
Question 12 options:
Dot |
|
Bitwise |
|
Logical |
|
Comparison |
Question 13
Question 13 options:
What would be printed from the following C++ program?
#include
#include
using namespace std;
struct Point
{
int x;
int y;
};
void makeTriangle(Point p[]);
int main()
{
Point p[3];
int i;
makeTriangle(p);
cout<<"The triangle consists of the following coordinates:\n";
for(i=0 ;i<3;i++)
cout<<"("<
return 0;
}
void makeTriangle(Point p[]){
p[0].x = 200;
p[0].y = 20;
p[1].x = 150;
p[1].y = 100;
p[2].x = 300;
p[2].y = 100;
}
Question 14 :
A ________ contains the memory address of a variable that in turn contains the specific value.
Question 15
In the programming segment below, the output is “30”?
int numbers[] = {10, 20, 30, 40, 50};
cout << "The third element in the array is ";
cout << *numbers + 2 << endl;
Question 15 options:
True | |
False |
Question 16
The ________ _______ is used to ______ a pointer.
Question 17
mustring.end() returns an iterator pointing to the last character of the string in mystring
Question 17 options:
True | |
False |
Question 18
The first n characters of the character array str are appended to mystring using which statement below.
Question 18 options:
mystring.assign(str, n) |
|
mystring.append(str, n) |
|
mystring.append(sx, n) |
|
mystring.append(str, n, x) |
Question 19
_______ is the library needed to conduct character testing (such as isalpha()).
Question 20
__________________ returns a copy of a substring. The substring is n characters long and begins at position x of mystring
Question 20 options:
mystring.substr(x-1, n) |
|
mystring.substr(x, n-1) |
|
mystring.substr(x, n) |
|
mystring.substr(x, n+1) |
|
mystring.substr(x+1, n) |
Question 11:
Correct Answer: True
Explanation:
The given statement is true because both function will return the length of the string.
For example:
string str = "abc";
cout<<str.length()<<endl;
cout<<str.size()<<endl;
OUTPUT:
3
3
Question 12:
Correct Answer: Dot
Explanation:
A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.
So, only first option is the correct option.
Question 13:
Correct Answer:
The triangle consists of the following coordinates:
(200, 20)
(150, 100)
(300, 100)
Explanation:
The given program source code has syntx error in the below statement:
cout<<"("<
To correct the syntax error, the given statement should be replaced with the below statement:
cout<<"("<<p[i].x<<", "<<p[i].y<<")"<<endl;
After replacing the above statement, the output of the given source code will be:
The triangle consists of the following coordinates:
(200, 20)
(150, 100)
(300, 100)
Question 14:
Correct Answer: pointer variable
Explanation:
A pointer variable is a special type of variable that is used to store the address of another variable which has a similar data type as the pointer data type. The dereferenced operator '*' is used to access the value stored at that location that is stored by the pointer variable.
For example:
int a = 10;
int *b = &a;
Here, the variable 'b' is a pointer variable that stores the address of an integer type variable.