What happens when you attempt to compile and run the following code?
#include <iostream> using namespace std;
int main(){
int i = 1;
if (--i==1) {
cout << i;
} else {
cout << i-1;
}
return 0;
}
A. It prints: 0
B. It prints: 2
C. It prints: 1
D. It prints: -1
正解:D
質問 2:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x=2, *y;
y = &x;
cout << *y + x;
return 0;
}
A. It prints: 0
B. It prints: 2
C. It prints: 4
D. It prints: 1
正解:C
質問 3:
Which of the following is a logical operator?
A. !
B. ||
C. &&
D. &
正解:A,B,C
質問 4:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
struct {
int x;
char c;
union {
float f;
int i;
};
} s;
int main (int argc, const char * argv[])
{
s.x=10;
s.i=0;
cout << s.i << " " << s.x;
}
A. It prints: 11
B. Compilation error
C. It prints: 0 10
D. None of these
正解:C
質問 5:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this->s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o->Print();
}
A. It prints: Sample
B. It prints: Sample text
C. None of these
D. It prints: text
正解:B
質問 6:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const int x=0;
const int *ptr;
ptr = &x;
cout<<*ptr;
return 0;
}
A. Compilation error
B. It prints: 0
C. It prints: 1
D. It prints address of x
正解:B
質問 7:
Which code, inserted at line 8, generates the output "0102020"?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
//insert code here
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.Print();
a.setAge(10);
a.Print();
b->setAge();
a.Print();
b->Print();
return 0;
}
A. void setAge(int a) {age = a;}
B. void setAge() {age = 20;}
C. void setAge(int a=20) {age = a;}
D. void setAge() {age = 10;}
正解:C
質問 8:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x,y=10;
float f;
f = 5.20;
x=(int) f;
cout << x <<", ";
f=float (y);
cout << f;
return 0;
}
A. It prints: 5.20, 10.0
B. It prints: 5, 10
C. It prints: 5.2, 10
D. It prints: 5.2, 10.00
正解:B
稲森** -
CPA過去問を徹底研究し、繰り返し出題されている頻出の過去問(類似問題)のみを厳選して掲載しているね。