Back to main >

CPP  Practice Test

You have chosen to take "CPP Skills Test" of 20 of 20 questions to be answered. All the questions are of 1 mark each. Once you got finish the test, total score will be shown. You can record your score to SiliconIndia account which will get added to your profile.
1. class complex{ double re; double im; public: complex() : re(0),im(0)
{} complex(double n) { re=n,im=n;}; complex(int m,int n) {
re=m,im=n;} void print() { cout<c3; double i=5; c3 = i; c3.print(); }
5 5 no out put syntax error Compiler Error
2. class some{ public: ~some() { cout<<"some's
destructor"<
some's destructor
some's destructor some's destructor
syntax error
Compiler Error
3. void main() { int d=5; printf("%f",d); }
output undefined no out put syntax error Compiler Error
4. class base { public: void baseFun(){ cout<<"from
base"< void baseFun(){ cout<< "from derived"<SomeFunc(base *baseObj) { baseObj->baseFun(); } int main() { base
baseObject; SomeFunc(&baseObject); deri
deriObject; SomeFunc(&deriObject); }
from base from base from base syntax error Compiler Error
5. #include main() { char *p1; char *p2; p1=(char *)
malloc(25); p2=(char *)
malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf(
"%s",p1); }
Ramco system no Compiler
6. void main() { char *s="\12345s\n"; printf("%d",sizeof(s)); }
6 5 4 2
7. void main() { unsigned i=1; /* unsigned char k= -1 => k=255; */ signed j=-1;
/* char k= -1 => k=65535 */ /* unsigned or signed int k= -1 =>k=65535
*/ if(ij) printf("greater"); else if(i==j)
printf("equal"); }
less equal greater no output
8. 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; icout<bval; cout<BaseArr[5]; SomeFunc(BaseArr,5); deri DeriArr[5]; SomeFunc(DeriArr,5); }
00000 01010 01010 00000 syntax error Compiler Error
9. void main() { int a, *pa, &ra; pa = &a; ra = a; cout <<"a="<<<"*pa="<<*pa <<"ra"<
some garbage value
no out put
syntax error
Compiler Error: 'ra',reference must be initialized
10. #include main() { char s1[]="Ramco"; char
s2[]="Systems"; s1=s2; printf("%s",s1); }
some garbage value
no out put
syntax error
Compilation error giving it cannot be an modifiable 'lvalue'
11. main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d
%d\n",x,y); }
57 94 94 57 syntax error Compiler Error
12. #define MAN(x,y) (x)>(y)?(x):(y) {int i=10; j=5; k=0;
k=MAX(i++,++j); printf(%d %d %d %d,i,j,k); }
10 5 0 0 5 10 syntax error Compiler Error
13. void main() { char *s[]={ "dharma","hewlett-packard","siemens","ibm"}; char
**p; p=s; printf("%s",++*p); printf("%s",*p++); printf("%s",++*p); }
harma siemens ewlett-packard Compiler
14. class Sample { public: int *ptr; Sample(int i) {
ptr = new int(i); } ~Sample() { delete
ptr; } void PrintVal() { cout << "The value
is " << *ptr; } }; void SomeFunc(Sample x) { cout << "Say i am in
someFunc " << endl; } int main() { Sample s1=
10; SomeFunc(s1); s1.PrintVal(); }
Say i am in someFunc Null pointer assigment (runtime error)
no out put
syntax error
Compiler Error
15. main() { char *ptr = "Ramco
Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); }
Samco Systems Ramco Systems no output Compiler Error
16. char *foo() { char result[100]); strcpy(result,"anything is
good"); return(result); } void main() { char
*j; j=foo() printf("%s",j); }
anything is good. no out put syntax error Compiler Error
17. void main() { float j; j=1000*1000; printf("%f",j); }
1000000 syntax error no output noen
18. main() {int i=0; for(i=0;i<20;i++) {switch(i) case 0:i+=5; case
1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } }
0,5,9,13,17 5,9,13,17 no output 16,21
19. #define AREA(x)(3.14*x*x) main() {float
r1=6.25,r2=2.5,a; a=AREA(r1); printf("\n Area of the circle is %f",
a); a=AREA(r2); printf("\n Area of the circle is %f", a); }
Area of the circle is 122.656250 Area of the circle is 19.625000
no out put
syntax error
Compiler Error
20. const int size = 5; void print(int *ptr) { cout<print(int ptr[size]) { cout<{1,2,3,4,5}; int *b = new int(size); print(a); print(b); }
some garbage value
no out put
syntax error
Compiler Error : function 'void print(int *)' already has a body
 
SiliconIndia About Us   |   Contact Us   |   Help   |   Community rules   |   Advertise with us   |   Sitemap   |   Question & Answer
News:       Technology   |   Enterprise   |   Gadgets   |   Startups   |   Finance   |   Business   |   Career   |   Magazine  |   Newsletter   |   News archive  
Cities:        CEO   |     Startup   |   Mobile   |   CIO   |   Women   |   BI   |   HR   |   SME   |   Cloud   |   Marketing   |   QA   |   Java   |   Web Developer  
Community:      Members   |   Blogs   |   Mentorship   |   Indian Entrepreneurs   |   Gyan   |   Advice   |   Community   |   Find   |   Events   |   CXO Insights  
Job Board:      Jobs   |   Freshers   |   Companies   |   HR Speak   |   Forum  
Online Courses:   Web Developer   |   Java Developer   |   CCNA Training   |   SEO   |   SAS   |   SQL Server 2005   |   J2EE
Education:   MBA   |   MCA   |   Engineering   |   Overseas Education   |   Training Institute
Life:          Real Estate   |   Travel   |   Finance   |   Gadgets   |    Products   |   Movie Reviews   |    Jokes   |   Videos 
Send your and help us continue to improve SiliconIndia
© 2013 SiliconIndia all rights reserved