C++ Interview Questions - CGI

1. Find the output of the following given program?

main()
{
int a[]={ 2,4,6,8,10 };
int i;
change(a,5);
for( i = 0; i <= 4; i++)
cout<}
change( int *b, int n){
int i;
for( i = 0; i < n; i++)
*(b+i) = *(b+i) + 5;}

2.What is the value of a and b of the following program?

s=0; c=a; d=b;
while(d<>0)
{ s=s+c;
d=d-1;
}
Cout<
3.What is the value of a and b of the following program?

while(3a+2b<100)
{ s=s+a;
a=a+2; b=b-1;
}

4.What is the value of a, s and c of the following given program?

S= 0; C = 0
Read A,B
While ((2A+3B) < 100)
{ S = 3A - 2B
c = c + 1
}
cout<
5.Write a program to reverse a single linked list?
6.How can you optimize the code given below?

for(int i=0;ival1;i++)
{
cout<< “inside the loop”;
}
Post your comment