C++/ Java Interview Questions - Calsoft

1. What is the output of the following program?

#include
main()
{
extern int a;
cout<}
int a=20;

(a) 20 (b) 0 (c) Garbage value (d) error

2. What is the output of the following program?

main()
{
int a[5]={2,3};
cout<}

(a) Garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0

3. What is the output of the following program?

main()
{
inti=-3,j=2,k=0,m;
m=++i&&++j||++k;
cout<}

(a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) error

4. What is the output of the following program?

main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
cout<}
sumdig(int n)
{
static int s=0;
int d;
if(n!=0)
{
d=n%10;
n=(n-d)/10;
s=s+d;
sumdig(n);
}
else return(s);
}

(a) 12 6 (b) 6 12 (c) 3 15 (d) error

5. What is the output of the following program?

#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
cout<}

(a) 64 4 (b) 27 4 (c) 27 6 (d) 64 6
Post your comment