63 227
Assignments Done
Successfully Done
In July 2018

Answer to Question #9674 in C# for kim

Question #9674
Consider the code
*a = "xyx", *b = "xyz";
if ( a==b )
printf("The two strings have the same address!\n");
printf("As I expected, the addresses are different.\n");
The expression a==b compares pointer values, not the contents of the strings.
Also, the expression a=b is an assignment of a pointer value, not an assignment
of a string. In this exercise we want to consider = and == with respect to their
use with structures. Suppose now that a and b are two structure variables of the
same type. The expression a=b is valid, but the expression a==b is not. The
operands of the == operator cannot be structures. Write a small test program to
see what your compiler does if you try to use the expression a==b, where a and
b are structures of the same type.
Expert's answer
#include <iostream>
using namespace std;

struct testStructure {

int main ()
& testStructure test1;
& testStructure test2;
& cout << test1==test2;
& system("pause");
& return 0;
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'testStructure' (or there is no acceptable conversion)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions