What is the output of the following code in C++?

Question: What is the output of the following code in C++?

int num;

int y=0;

cin >> num = 7;

while ( num > 0 )

{

num = num / 10;

y++;

}

cout << y;

(A). 1

(B). 2

(C). 10

(D). 11

(E). None of these

Answer of Multiple Choice Question: (A). 1


Question: Find the output of the following code.

float NO, b=3;

cin >> NO;

b = pow ( NO, 0.5 );

cout << b << endl;

(A). 5

(B). 2.73

(C). 1.73

(D). 9

(E). None of these

Answer of Multiple Choice Question: (C). 1.73


Question: Give the output of the following code segment?

int a = 0,b = 1,t,j = 1,num = 5;

cout << a << b;

do

{

t = a + b;

cout << t;

a = b ;

b = t;

j++;

}

while (j <=num );

(A). 0112358

(B). 0224678

(C). 2

(D). 3

(E). None of these

Answer of Multiple Choice Question: (A). 0112358


Question: What is the output of the following lines of code?

int a = 2,b =1, t, j = 1, num = 5;

cout << a << b;

do

{

t = a + b;

a = b + t;

cout << t;

j++;

}

while ( j <= num );

(A). 21357912

(B). 21357913

(C). 21357911

(D). 21357914

(E). None of these

Answer of Multiple Choice Question: (C). 21357911


Question: What is the output produced by the following code?

int z;

int number = 99;

int g = 0;

while ( number > 0 )

{

z = number % 10;

number = number / 10;

g = g + z;

}

cout << g;

(A). 9.9

(B). 10.9

(C). 9.9

(D). 18

(E). None of these

Answer of Multiple Choice Question: (D). 18


Question: What will be the output of the following code?

int j;

int h = 0;

int numbers = 10;

for( j = 1; j <= numbers; j++ )

{

h =  h + j;

cout << j;

}

cout << h;

(A). 12345678910

(B). 1234567891055

(C). 123456789

(D). 1234567890

(E). None of these

Answer of Multiple Choice Question: (B). 1234567891055


Question: What is the output of the following code snippet?

int num = 5;

int array [10], k = 0;

int n;

while ( num > 0)

{

array[k] = num%2;

num = num / 2;

k++;

}

for( n = k-1; n>=0; n– )

{

cout << array[n];

}

(A). 101

(B). 1011

(C). 111

(D). 0101

(E). None of these

Answer of Multiple Choice Question: (A). 101


Question: What is the output of the following code snippet?

char a[10] = “T4”;

char b[10] = “Tutorials”;

cout << a << endl;

cout << b <<endl;

strcat ( a ,b );

cout << a;

getch();

(A).

T4

Tutorials

T4

(B).

T4

Tutorials

T4Tutorials

(C).

T4

Tutorials

T4

Tutorials

(D). Both a and b

(E). None of these

Answer of Multiple Choice Question: (B).

T4

Tutorials

T4Tutorials

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.