Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What are actual and formal parameters of a function?

Answer»

The arguments passed to the functions while the function is called is known as the actual arguments, whereas the arguments declared in the function header is called as formal arguments.

Ex. Suppose sum() is a function.

int sum(int x, int y) /*Here x and y are called formal arguments*/ {...}

void main() { 

int ans; 

.... 

ans = sum(3,5); /*Here the arguments 3 and 5 are called actual arguments*/

...

 getch();

}

2.

How does OOP overcome the shortcomings of traditional programming approaches?

Answer»

OOP provides the following advantages to overcome the shortcomings of traditional programming approaches: 

OOPs is closer to real world model.

Hierarchical relationship among objects can be well-represented through inheritance.

Data can be made hidden or public as per the need. Only the necessary data is exposed enhancing the data security.

Increased modularity adds ease to program development.

Private data is accessible only through designed interface in a way suited to the program. 

3.

What is the output of the program? #include void main(){ int x,y,z;;; x=0;y=1;z=2;;;; x=y+z; clrscr(); printf("%d",x); printf(",%d",y); getch( ); }(a) will compile b) will not compile

Answer»

Correct option: (a) will compile

Reason: ;;; does not matter. This indicates only an empty statement. The o/p will be 3,1

4.

What is the output of the program? void main() {  char ptr1[]="goat"; char ptr2[]="good"; clrscr(); if(strcmp(ptr1,ptr2)>0)printf("good job");elseprintf("nice job");}a) good job b) nice job c) error

Answer»

Correct option: b) nice job

Reason: unsolved

5.

What is the output of the program?void main ( ){char c[5]; int x;}abc[];  abc[]={"lird",10,"labs",20,"research",30};  printf("%s",abc[1].c);  printf(",%d",abc[2].x); } a) errorb) labs,20 c) labs,30 d) labs,10 

Answer»

Correct option: a) error

reason: you cannot declare structure as unsized array. 

6.

What is the output of the program? int add (int x); void main( ) { int y;  y=add(3);  clrscr();  printf("%d",y); } add(int x){ return (x--); } a) 4 b) 3 c) 2 d) error 

Answer»

Correct option: b) 3

Reason: The return st.. returns x value first as it is and then decrements its value. Its post decrement.

7.

How are the following two statements different?char pcode = 75;short pcode = 75;

Answer»

The first statement treats 75 as ascii value and converts it into its relative character ‘K’ whereas second statement treats 75 as number.

8.

If value is an identifier of int type and is holding value 200, is the following statement correct?char code = value

Answer»

VALID  Statement

9.

What values will be assigned to the variables ua, ub, uc and fail after the execution of the following program segment:void main() {int i = 0,ua = 0,ub = 0,uc = 0,fai l= 0;while(i<=5){switch(i++){ case 1:case 2: ++ua;case 3:case 4: ++ub;case 5: ++uc;default: ++fai;} //switch} //whilecout<<ua<<end1;cout<<ub<<end1;cout<<uc<<end1;cout<<fail<<end1;}

Answer»

Values assigned to the variables ua, ub, uc and fail after the execution are as following:

ua = 2

ub = 4

uc = 5

fail = 6

10.

What are arithmetic operators in C++? Distinguish between unary and binary arithmetic operators. Give examples for each of them.

Answer»

Following are the arithmetic operators in C++:

addition(+), subtraction(-), multiplication(*), division(/) and reminder(%).

Unary arithmetic operatorsBinary arithmetic operators 
Unary Operators has only one operandBinary operators (”bi” as in “two”) have two operands 
The Unary Operators are ++,--,&,*,+, - etc.The +, -, &&, <<, ==, >> etc. are binary operators.
Example: short x = 987; x = -x;Example:  int x, y = 5, z;
z = 10; x = y + z;
11.

Discuss the similarities and difference between global and local variables in terms of their lifetime and scope. 

Answer»

Local variable
Global variable
It is a variable which is declared within a function or within a compound statement.It is a variable which is declared outside all the functions.
It is accessible only within a function/compound statement in which it is declaredIt is accessible throughout the program
A global variable comes into existence when the program execution starts and is destroyed when the program terminates.A local variable comes into existence when the function is entered and is destroyed upon exit.

Example:

#include <iostream.h>

float NUM=900; 

//NUM is a global variable

void LOCAL(int T)

{

int Total=0; //Total is a local variable

for (int I=0;I<T;I++)

Total+=I; cout<<NUM+Total;

}

void main() {

LOCAL(45);

}

12.

The data type double is another floating-point type. Then why is it treated as a distinct data type?

Answer»

The data type double is treated as a distinct data type because it occupies twice as much memory as type float, and stores floating-point numbers with much larger range and precision. It stands for double precision floating-point. It is used when type float is too small or insufficiently precise.

13.

Explain the impact of access modifier const over variables. Support your answer with examples. 

Answer»

The access modifier const can be added to the declaration of an object to make that object a constant rather than a variable. Thus, the value of the named constant cannot be altered during the program run whereas the value of the variable can be changed during the program run.

Example:

void main ()  {

const int a =10;

int b = 20;

a++;

cout<<"a="<<a;

b++;

cout<<"b="<<b;

}

14.

Is it possible to create mobile apps with python?

Answer»

Yes it is possible to create mobile apps using Python.

Kivy is a powerful library based on Python for the development of mobile apps including the natural user interface (NUI).

Yes, it is.

You can also use a python package named as "Pygame" to create amazing and awesome games.
15.

The following code is from a game, which generates a set of 4 random numbers. Praful is playing this game, help him to identify the correct option(s) out of the four choices given below as the possible set of such numbers generated from the program code so that he wins the game. Justify your answer.#include&lt;iostream.h&gt;#include&lt;stdlib.h&gt;const int LOW=25;void main() {randomize ();int POINT=5,Number;for(int I=1;I&lt;=4;I--){Number=LOW+random(POINT);cout&lt;&lt;Number&lt;&lt;":";POINT--;}}(i)  29:26:25:28:(ii)  24:28:25:26:(iii)  29:26:24:28:(iv)  29:26:25:26:

Answer»

(iv) 29: 26: 25: 26: is correct

Justification: 

The only option that satisfied the values as per the code is option (iv) because when:

IPOINTNumber
MinimumMaximum
152529
242528
332527
422526
16.

Find the output of the following program:#include&lt;iostream.h&gt;void SwitchOver(int A[],int N,int split){ for(int K=0;K&lt;N;K++)  if(K&lt;Split)  A[K]+=K;else  A[K]*=K; }void Display(it A[],int N){ for(int K=0;K&lt;N;K++) (K%2==0)?cout&lt;&lt;A[K] &lt;&lt;"%":cout&lt;&lt;A[K]&lt;&lt;end1;}void main() {   int H[ ]={30,40,50,20,10,5};   SwitchOver(H,6,3);   Display(H,6);}

Answer»

Output: 

30%41 

52%60 

40%25

17.

What do you understand by two-dimensional arrays? State some situation that can be easily represented by two- dimensional arrays.

Answer»

Two-dimensional array:

A two-dimensional array is an array in which each element is itself an array. For instance, an array A[m][n] is an M by N table with M rows and N columns containing M x N elements. Two-dimensional arrays are used to represent tables, matrices, etc.

For example, below marks table can be represented easily by 2D array :

MathsPhysicsChemistryCSEnglisgToal
Amit6064648279349
Chandar8470827969349
Lalit7968868785698
18.

What do you understand by default arguments and constant argument? Write a short note on their usefulness. 

Answer»

Default arguments:

C++ allows us to assign default values to a function’s parameters which are useful in case a matching argument is not passed in the function call statement. The default values are specified at the time of function declaration.

Example: float interest(float principal, int time, float rate=0.10); 

Constant argument: By constant argument, it is meant that the function cannot modify these arguments. In order to make an argument constant to a function, we can use the keyword const as shown : int sum (const int a, const int b); The qualifier const in function prototype tells the compiler that the function should not modify the argument. The constant arguments are useful when functions are called by reference.

19.

Can you think of a difference between an array of strings and other two-dimensional arrays? What is it? Support your answer with examples.

Answer»
Array of stringsTwo-dimensional array
Array of string is used to store string value.Two-dimensional array is used to store numeric value.
The first index determines the number of strings and the second index determines maximum length of each string.The first index determines the number of rows and the second index determines maximum columns of each string.
Example:
int a[2][3];
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<3;++j)
{
cout<<"Enter element:";
cin>>a[i][j];
}
}
Example:
char string[3][31];
int i;
cout<<"Enter 3 strings:"; for(i=0;i<3;i++)
cin.getline(string[i],31);
20.

Illustrate the concept of Inheritance with the help of an example.

Answer»

Inheritance is the capability of one class to inherit properties from another class. For instance, Student is a class wherefrom class GraduateStudent inherits as given below:

class Student

{

protected:

char name[25];

int rollno;

public:

void readStudent();

void showStudent();

};

class GraduateStudent:protected Student

{

protected:

char subjects[50];

public:

void readAradStud();

void showGradStud();

};

21.

Discuss the relation between abstract and concrete classes.

Answer»

In C++ an Abstract Class is the one, which defines an interface, but does not necessarily provide implementation for all its member functions. An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the member functions that are not implemented in the base class. A derived class that implements all the missing functionality is called a Concrete Class. A concrete class derives from its abstract class.

22.

Find the output of the following program:#include&lt;iostream.h&gt;#include&lt;ctype.h&gt;void MyCode(char Msg[],char CH){for(int Cnt=0;Msg[cnt]!='\0';Cnt++){if(Msg[Cnt]&gt;='B' &amp;&amp; Msg[Cnt]&lt;='G')Msg[Cnt]=tolower(Msg[Cnt]);elseif(Msg[Cnt]&gt;='A' &amp;&amp; Msg[Cnt]&lt;='a')Msg[Cnt]=CH;elseif(Cnt%2==0)Msg[Cnt]=toupper(Msg[Cnt]);elseMsg[Cnt]=Msg[Cnt-1];}}void main() {char MyText[]="ApEACeDriVE";MyCode(MyText,'@');cout&lt;&lt;"NEW TEXT:"&lt;&lt;MyText&lt;&lt;end1;

Answer»

Output:

NEW TEXT:[email protected]@e

23.

Give the output of the following: #include&lt;iostream.h&gt;void Execute(int &amp;B,int C=200){int TEMP=B+C;B+=TEMP;if(C==100)cout&lt;&lt;TEMP&lt;&lt;B&lt;&lt;C&lt;&lt;end1;}void main() {int M=90,N=10;Exwcute(M);cout&lt;&lt;M&lt;&lt;N&lt;&lt;end1;Exwcute(M,N);cout&lt;&lt;m&lt;&lt;N&lt;&lt;end1;}

Answer»

Output

38010

77010

24.

What are the advantages offered by inheritance?

Answer»
  • Inheritance ensures the closeness with the real-world models.
  • Allows the code to be reused as many times as needed. The base class once defined and once it is compiled, it need not be reworked. 
  • We can extend the already made classes by adding some new features.
  • Inheritance is capable of simulating the transitive nature of real-world’s inheritace, which in turn saves on modification time and efforts, if required.
25.

Discuss major OOP concepts briefly.

Answer»

Following are the general OOP concepts:

1. Data Abstraction: Data abstraction means, providing only essential information to the outside word and hiding their background details i.e. to represent the needed information in program without presenting the details.

2. Data Encapsulation: The wrapping up of data and operations/functions (that operate o the data) into a single unit (called class) is known as Encapsulation.

3. Modularity: Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

4. Inheritance: Inheritance is the capability of one class of things to inherit capabilities or properties from another class.

5. Polymorphism: Polymorphism is the ability for a message or data to be processed in more than one form. 

26.

What main integer types are offered by C++?

Answer»

C++ offered three types of integers : short, int and long. Each comes in both signed and unsigned versions. 

27.

Find out the errors, if any, in the following C++ statement:(i)  cout&lt;&lt;" = "a;(ii)  m = 5, n = 12; o = 15(iii)  cout&lt;&lt;"x";&lt;&gt;y;&gt;&gt;j;(v)  cin&gt;&gt;"\n"&gt;&gt;y; (vi)  cout&gt;&gt;"\n "abc";(vii)  a = b + c(viii)  break = x*y;

Answer»

(i) cout<<"="a;

(ii)  m = 5, n = 12; o = 15

(iii)  cout<<"x";<<x;

(iv) cin>>y;>>j;

(v)  cin>>"\n">>y;

(vi)  cout>>"\n "abc";

(vii)  a = b + c

(viii)  break = x*y;

28.

How are classes and objects implemented in C++? 

Answer»

A class is a blueprint for object. A class is implementing with the help of an object. Suppose a class has a member function named display(). Now, to implement that member function display we have to use object of that class.

The objects is implemented in software terms as follows: 

(i) characteristics / attributes are implemented through member variables or data items of the object.

(ii) behavior is implemented through member functions called methods.

(iii) It is given a unique name to give it identify

29.

Give the output of the following:#include&lt;iostream.h&gt;void Execute(int &amp;X,int Y=200){int TEMP = X+Y;X+=TEMP;if(Y!=200)cout&lt;&lt;TEMP&lt;&lt;X&lt;&lt;Y&lt;&lt;end1;}void main () {int A=50,B=20;Exwcute(B);cout&lt;&lt;a&lt;&lt;B&lt;&lt;end1;Exwcute(A,B);cout&lt;&lt;A&lt;&lt;B&lt;&lt;end1;

Answer»

Output:

50240

290340240

340240

30.

Give the output of the following program:(i) void main() {char *p = "Difficult";char c;c = ++*p++;printf("%c",c);}(ii)  #include&lt;iostream.h&gt;static int i = 100;void abc(){static int i = 8;cout&lt;&lt;"first="&lt;&lt;i;}main() {static int i = 2;abc();cout&lt;&lt;"second="&lt;&lt;i&lt;&lt;endl;}(iii)  #include&lt;iostream.h&gt;void Print(char *p){p="Pass";cout&lt;&lt;"Value is:"&lt;&lt;p&lt;&lt;end1;}void main(){char *q="Best of Luck";Printf(q);cout&lt;&lt;"New value is:"&lt;&lt;q;

Answer»

(i) Output:  E

(ii) Output:  first=8second=2

(iii) Output:  Value is: Pass

New value is: Best of Luck

31.

Find the output of the following program: #include&lt;iostream.h&gt;struct THREE_D{int X,Y,Z; };void MoveIn(THREE_D &amp;T,int Step=1){T.X+=Step;T.Y-=Step;T.Z+=Step;}void MoveOut(THREE_D &amp;T,it Step =1){T.X- = Step;T.Y+ = Step;T.Z- = Step;}void main() {THREE_D T1={10,20,5}, T2={30,10,40};MoveIn(T1);MoveOut(T2,5);cout&lt;&lt;T1.X&lt;&lt;","&lt;&lt;T1.Y&lt;&lt;","&lt;&lt;T1.Z&lt;&lt;end1;cout&lt;&lt;T2.X&lt;&lt;","&lt;&lt;T2.Y&lt;&lt;","&lt;&lt;T2.Z&lt;&lt;end1;MoveIn(T2,10);cout&lt;&lt;T2.X&lt;&lt;","&lt;&lt;T2.Y&lt;&lt;","&lt;&lt;T2.Z&lt;&lt;end1;

Answer»

Output:

11,19,6

25,15,35

35,5,45

32.

While implementing encapsulation, abstraction is also implemented. Comment.

Answer»

Abstraction is the act of representing essential features without including the background details. Encapsulation is the way of combining both data and the functions that operate on the data under a single unit. Encapsulation is the way of implementing abstraction. Thus, it is true that while implementing encapsulation, abstraction is also implemented.

33.

What is meant by unsized array initialization in C++? What are its benefits?

Answer»

Unsized array initialization means skip the size of the array I an initialization statement. The C++, then automatically creates an array big enough to hold all the initializers present and calculates the dimensions of unsized arrays.

Example: char S1 [ ] = “First String”;

Advantages:

  • Less tedious.
  • Allow to change any of the values without fear of using incorrect array dimensions.
  • We may lengthen or shorten the value-list without changing the array dimensions.
34.

If an array is initialized at the time of declaration, what thing one must bear in mind?

Answer»

The general form of array initialization is as shown below:

type array-name[size N] = {value-list};

If an array is initialized at the time of declaration, following thing one must bear in mind:

  • The element values in the value-list must have the same data type as that of type, the base type of the array.
  • In character array, you must make sure that the array you declare is long enough to include the null. 
35.

Find the output of the following program:#include&lt;iostream.h&gt;#include&lt;ctype.h&gt;void Encode&lt;char Info[],int N);void main() {char Memo[]="Justnow";Encode(Memo,2);cout&lt;&lt;Memo&lt;&lt;end1;}void Encode&lt;char Info[],int N){for(int I=0;Info[I]!='\0';I++)if(I%2==0)Info[I]=Info[I]-N;else if(islower(Info[I]))Info[I]=toupper(Info[I]);elseInfo[I]=Info[I]+N;

Answer»

Output:

HUqT10u

36.

How is polymorphism implemented in C++?

Answer»

C++ implements polymorphism through virtual functions, overloaded functions and overloaded operators. The term ‘overloaded function’ refers to a function having one name and more than one distinct meaning.

For example,

float area(float a)

{

return a*a;

}

float area(float a,float b)

{

return a*b;

}

37.

What is an array? What is the need for array?

Answer»

Array: An array is a collection of variables of the same type that are referenced by a common name.

Need for array: Arrays are very much useful in a case where many variables of the same (data) types need to be stored and processed. For example, suppose we have to write a program in which can accept salary of 50 employees. If we solve this problem by making use of variables, we need 50 variables to store employee’s salary. Remembering and managing these 50 variables is not an easy task and it will make the program a complex and lengthy program. This problem can be solved by declaring 1 array having 50 elements; one for employee’s salary. Now we only have to remember the name of that 1 array.

38.

Find the output of the following program:#include&lt;iostream.h&gt;void main() {int First=25,Sec=30;for(int I=1;I&lt;=2;I++0{ cout&lt;&lt;"Output1="&lt;&lt;First++&lt;&lt;"&amp;"&lt;&lt;Sec+5&lt;&lt;end1;cout&lt;&lt;"Output2="&lt;&lt;-Sec&lt;&lt;"&amp;"&lt;&lt;First-5&lt;&lt;end1;}}

Answer»

Output: 

Output1=25&35

Output2=-30&21

Output1=26&35

Output2=-30&22

39.

Find the output of the following program:#include&lt;iostream.h&gt;#include&lt;ctype.h&gt;void main(){char Line[]="[email protected]";for(int I=0;Line(I)!='\0';I++){if(!isalpha(Line[I]))Line[I]='$';else if(islower(Line[I]))Line[I]=Line[I]+1;elseLine(I)=Line[I+1];}cout&lt;&lt;Line;}

Answer»

Output: 

Oppe$0GIC

40.

Write briefly about different programming paradigms.

Answer»

Programming Paradigm: 

A Programming Paradigm defines the methodology of designing and implementing programs using the key features and building blocks of a programming language.

Following are the different programming paradigms:

(i) Procedural Programming: Procedural programming paradigm lays more emphasis on procedure or the algorithm. Data is considered secondary. Data is loosely available to many functions. This paradigm is: Decide which procedure we want; use the best algorithm we can find.

(ii) Object Based Programming: In object based programming, data and its associated meaningful functions are enclosed in one single entity a class. Classes enforce information hiding and abstraction thereby separating the implementation details and the user interface. It also supports user-defined types.

(iii) Object Oriented Programming: Object oriented programming offers all the features of object based programming and overcomes its limitation by implementing inheritance. The object oriented approach views a problem in terms of objects involved rather than procedure for doing it. We can define the object oriented programming (OOP) paradigm as following: Decide which classes and objects are needed; provide a full set of operations for each class. 

41.

How do the following two statements differ in operation?cin&gt;&gt;ch;cin.get(ch);

Answer»

The difference between cin>>ch and cin.get(ch) is that when >> operator is used, the white spaces (e.g., tabs), spaces etc. and new-line characters are ignored whereas it is not so with cin.get(ch). 

42.

Find the output of the following program:#include&lt;iostream.h&gt;#include&lt;ctype.h&gt;void main(){char Line[]="[email protected]";for(int I=0;Line(I)!='\0';I++){if(!isalpha(Line[I]))Line[I]='$';else if(islower(Line[I]))Line[I]=Line[I]+1;elseLine(I)=Line[I+1];}cout&lt;&lt;Line;}

Answer»

Output: 

Oppe$0GIC

43.

Study the following program and select the possible output from it:#include&lt;iostream.h&gt;#include&lt;stdlib.h&gt;const int LIMIT=4;void main() {randomize();int Points;points=100+random(LIMIT);for(int P=Pints;P&gt;=100;P--)cout&lt;&lt;P&lt;&lt;"#";cout&lt;&lt;end1;}(i)  103#102#101#100#(ii)  100#101#102#103#(iii)  100#101#102#103#104#(iv) 104#103#102#101#100#

Answer»

(i)  103#102#101#100#  

44.

Briefly describe the importance of iostream.h file. 

Answer»

iostream.h is most important header file for basic input and output operations. iostream.h contain built-in functions cout and cin for input-output. So, every C++ program should include iostream.h header file for performing input and output operations.

45.

What is the difference between Type Casting and Automatic Type conversion? Also, give a suitable C++ code to illustrate both.

Answer»
Type CastingAutomatic Type conversion
It is an explicit process of conversion of a data from one type to another.It is an implicit process of conversion of a data from one type to another.
It is performed with the help of casting operator(). It is performed by compiler its own.
Example:
int A=1, B=2;
float C = (float)A/B;//Type Casting
cout<<C;
Output: 0.5
Example:
int N = 65;
char C = N; //Automatic type conversion
cout<<C;
Output: A
46.

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of CNG by recording the miles driven and the gallons used for each tank.Develop a C++ program that will input the kilometers driven and gallons used for each tank. The program should calculate and display the kilometers per gallon obtained for each tank of gasoline. After processing all input information, the program should calculate and print the average kilometers per gallon obtained for all tanks.Formulate the algorithm as flowchart.Write a C++ program as instructed.Test, debug, and execute the C++ program.

Answer»

#include<iostream.h>

#include<conio.h>

void main() {

clrscr();

int tanks=0;

float tot_km; float avg_k_p_g;

cout<<"Enter how many tanks filled :";

cin>>tanks;

float *kms=new float[tanks];

float *gallons_used=new float[tanks];

float *k_p_g=new float[tanks];

for(int i=0;i<tanks;i++)

{

cout<<"Enter how much kilometers covered for tank "<<i+1<<" ";

cin>>kms[i];

cout<<"Enter how much gallon used from tank "<<i+1<<" ";

cin>>gallons_used[i];

k_p_g[i]=kms[i]/gallons_used[i];

cout<<"KMs per Gallon obtained for tank No. "<<i+1<<" "<<k_p_g[i]<<endl;

tot_km+=k_p_g[i];

cout<<endl;

}

avg_k_p_g=tot_km/tanks;

cout<<"Average kilometers per gallon obtained for all tanks is "<<avg_k_p_g;

getch();

}

47.

Is it necessary to include a header file in a program? If it is not done, what happens? 

Answer»

No, it is not necessary to include header file in a C++ program at all. A header file is included if only the program intends to use the functions or macros etc. defined in that particular header file.

48.

Write a program that asks the user to enter two integers, obtains the two numbers from the user, and outputs the large number followed by the words “is larger by – units than smaller number” to the system console (e.g., if the larger number is 9 and smaller is 6, message should be “9 is larger by 3 units than smaller number”). If the numbers are equal print the message “These numbers are equal”. 

Answer»

#include<iostream.h>

#include<conio.h>

void main()

{

int a,b,dif;

clrscr(); 

cout<<"Enter a:";

cin>>a;

cout<<end1<<"Enter b: ";

cin>>b;

if(a>b)

{

dif = a-b;

cout<<a<<" is larger by " <<diff<<"units than smaller number"<<end1;

}

else if(b>a)

{

dif = b-a;

cout<<b<<"is larger by"<<dif<<"units than smaller number"<<end1;

}

else

cout<<"These numbers are equal"<<end1;

getch();

49.

What are the outputs of following two codes fragments? Justify your answer.//version 1                f = 1, i =2;   while(++i &lt; 5) f * = i;cout&lt;&lt;f;:://version 2 intint f = 1, i = 2;do{f * = i;}while (++i &lt; 5); cout&lt;&lt; f;:

Answer»

The output of the first code fragment is 12.

The output of the first code fragment is 24.

50.

Identify the possible error(s) in the following code fragment. Discuss the reason(s) of error(s) and correct the code:cin&gt;&gt;i&gt;&gt;j;while(i&lt;j) cout&lt;,i*j;i++;

Answer»

Correct code:

cin>>i>>j;

while(i<j)

{

cout<<i * j;

i++;

}

Reasons of errors:

(i) There is a use of ‘<,’ in cout statement instead of ‘<<’ which is not valid.

(ii) while statement should be in curly braces otherwise it will not work properly.