C++ Quiz



C++ Quiz at csepedia.org

1. What will be the output of following code :-

void main()
{
int x=10,y=15;
x=x++;
y=++y;
cout<<x<<y;
}

A. 10,15
B. 10,16
C. 11,15
D. 11,16


2. The keyword used to transfer control from a function back to the calling function is

A. switch
B. goto
C. return
D. go back


3. What will be the output of following code :-

void main()
{
int a=5;
int b=10;
int c=(a>b?a:b);
cout<<c;
}

A. 5
B. 10
C. Compiler Error
D. 5:10


4. What will be the output of following code :-

int a=1;
void main()
{
int a=2;
cout<<a;
}

A. 1
B. 2
C. Compiler Error
D. Run Time Error


5. What will be the output of following code :-

void main()
{
int a=0;
int b=(a=5, a+2);

cout<<b;
}

A. Syntax Error
B. Junk Value
C. 7
D. 5


6. ______ variables remain in the memory until the program ends.

A. Local
B. Global
C. Reference
D. Local Static


7. What will be the output of following code :-

void main()
{
int n=9;
int *p;
p=&n;
n++;
cout<<*p+2;
cout<<n;
}

A. 12,10
B. 11,10
C. Address of n+2, 10
D. Compiler Error


8. What will be the output of following code :-

#define WIN_XP
void main()
{
int a=0;

#ifdef WIN_7
a=10;

#elif defined(WIN_XP)
a=20;

#else
a=30;

#endif
cout<<a;
}

A. 30
B. 20
C. 10
D. Compiler Error


9. What will be the output of following code :-

void main()
{
int i=0;
int a=10;

if(i=0)
{
a=20;
}
else
{
a=30;
}
cout<<a;
}

A. 10
B. 20
C. 30
D. Compiler Error


10. What will be the output of following code :-

void main()
{
int i=1;
switch(i)
{
case 1:
cout<<"One";
case 2:
cout<<"Two";
break;
}
}

A. OneTwo
B. One
C. Two
D. Error : No break in case 1


11. What will be the output of following code :-

void main()
{
char a[10];
char b[10]="string";
int length=strlen(b);

for(int i=0;i<length;i++)
{
a[i]=b[length-i];
cout<<a[i];
}
}

A. gnirts
B. gnirt
C. string
D. No output is pinted


12. Which of the following statement creates infinite loop ?

A. for(;;)
B. while(1)
C. do{}while(1)
D. All of the above


13. The use of "break" statement

A. Termination of a loop
B. To Terminate a case in the switch statement
C. To exit the program
D. A and B


14. What will be the output of following code :-

#define MUL(a,b)(a*b)

int mul(int a,int b)
{
return a*b;
}

void main()
{
int i=2;
int j=4;
int k=MUL(i+3,j+2);
int l=mul(i+3,j+2);
cout<<k<<l;
}

A. 16,30
B. 30,30
C. 30,16
D. 16,16


15. What will happen if a file is opened using fopen and not closed using fclose ?

A. File will become unusable
B. Other programs cannot open the same file, as long as
          this program is running.
C. File will be corrupted
D. None of the above




CSE Quiz

Algorithms




Database Management




C++ Quiz 1

C++ Quiz 2




Digital Electronics





Data Structures




Computer Architecture




Computer Network




HTML





Automata Theory




Operating System