1.

Identify the errors in the following C++ code segment and give the reason for each.int p, *q a=5; float b2;p=&a;cout<<p<<*p<<*a;if(p<q)colLit<<p;cout<<cp*a;

Answer»

Following are the errors 

(1) Here q is an integer pointer it can not store the address of oat variable b. 

(2) Cannot print *a. 

(3) The pointers p and q are different data types so cannot use relational operator.

The correct code is as given below.

#include<iostream>

using namespace std;

int main()

{

int *p,a=5,*q,b=2;

p=&a;

q=&b;

cout<<p<<*q<<a;

if(p!=q)cout<<p;

cout<<*p*a;

}



Discussion

No Comment Found