Вы находитесь на странице: 1из 6

C/C++ Objective Test

Q1. Predict the output:

main()

printf(“%d”,4%3);

printf(“%d”,4%-3);

printf(“%d”,-4%3);

printf(“%d”,-4%-3);

a) 1111 b) 11-1-1 c) 1-1-11 d) 1-1-1-1

Q2. Which is the parameter that is added to every non-static member function when it is called?

a) Anyone b) dot c) this d) none

Q3. main()

int a=30, b=40,x;

x=(a!=10) && (b=50);

printf(“x=%d”,x);

a) 50 b) 0 c) 1 d) Error

Q4.class base
{
public:
int bval;
base(){ bval=0;}
};

class deri:public base


{
public:
int dval;
deri(){ dval=1;}
};
void SomeFunc(base *arr,int size)
{
for(int i=0; i‹size; i++,arr++)
cout«arr-›bval;
cout«endl;
}

int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}

a) 00000 b) 00001 c) 00000 d) 00001


01010 01001 10001 01010

Q5. class base


{
public:
virtual void baseFun(){ cout«"from base"«endl;}
};
class deri:public base
{
public:
void baseFun(){ cout« "from derived"«endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
a) from base b) from derived c) from base d)fromderived
from derived from base from base from derived
Q6. What will be the output of the following code?

void main ()
{ int i = 0 , a[3] ;
a[i] = i++;
printf (“%d",a[i]) ;
}

a) 0 b) 1 c) Garbage value d) Error

Q7. Are the following two statements identical?

char str[6] = "Kicit" ;


char *str = "Kicit" ;

a) Yes b) No c) can’t say d)Declaration error

Q8. class opOverload{


public:
bool operator==(opOverload temp);
};

bool opOverload::operator==(opOverload temp){


if(*this == temp ){
cout«"The both are same objects\n";
return true;
}
else{
cout«"The both are different\n";
return false;
}
}

void main(){
opOverload a1, a2;
a1= =a2;
}

a) The both are same objects b)The both are different c)Compile Time Error d)RunTime Error
Q9 class some{
public:
~some()
{
cout«"some's destructor"«endl;
}
};

void main()
{
some s;
s.~some();
}

a) Compile time error


b)Run time error
c) some’s destructor
d)some’s destructor some’sdestructor

Q10. #include
void main()
{
int cnt = 5, a;

do {
a /= cnt;
} while (cnt --);

printf ("%d\n", a);


}

a)5 4 3 2 1 b) 4 3 2 1 0 c) compile time error d)Run time error

Q11#include
main()
{
int k = 5;

if (++k < 5 && k++/5 || ++k <= 8);

printf("%d\n", k);
}

a) 5 b) 6 c) 7 d) 8
Q12 #include

void fn(int);

static int val = 5;

main()
{
while (val --) fn(val);
printf("%d\n", val);
}

void fn(int val)


{
static int val = 0;

for (; val < 5; val ++) printf("%d\n", val);


}
a) 1 2 3 4 5
b) 0 1 2 3 4 5
c) 0 1 2 3 4 1
d) 0 1 2 3 4 -1

Q13 class base


{
public:
virtual void baseFun(){ cout«"from base"«endl;}
};
class deri:public base
{
public:
void baseFun(){ cout« "from derived"«endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
a) from base b) from derived c) from base d)fromderived
from derived from base from base from derived
Q14 main()
{
Int x=3,z;
Z=x--- -1;
printf(“x=%d z=%d”,x,z);
}

a) Compile Time error b) 2,3 c)2,4 d)3,4

Q15. main()
{
Int x=3,z;
Z=x++ + ++x;
printf(“x=%d z=%d”,x,z);
}
a) 4,10 b)4,8 c)5,7 d)5,8

Вам также может понравиться