C++ Institute CPA-21-02 - CPA - C++ Certified Associate Programmer
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int min(int a, int b);
int main()
{
int b=10;
b = min(5,20);
cout << b;
return 0;
}
int min(int a, int b)
{
if (a
return(a);
else
return(b);
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void fun(char*);
int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[0]);
return 0;
}
void fun(char *a)
{
cout << *a;
}
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class Second;
class Base {
int age;
public:
Base () { age=5; };
friend void set(Base &ob, Second &so);
void Print() { cout << age;}
};
class Second {
string name;
public:
friend void set(Base &ob, Second &so);
void Print() { cout << name;}
};
void set(Base &ob, Second &so) {
ob.age = 0; so.name = "Bill";
}
int main () {
Base a;
Second b;
set(a,b);
a.Print();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int main()
{
const char *s;
char str[] = "Hello";
s = str;
while(*s) {
cout << *s++;
}
return 0;
}
What will the variable "y" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
};
class B : protected A {
string name;
public:
void Print() {
cout << name << age;
}
};
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int mul (int a, int b=2)
{
int r;
r=a*b;
return (r);
}
int main ()
{
cout << mul(1) << mul(2,4);
return 0;
}
A condition expression used by if(), while(), and do-while() must evaluate to and only to: