operands type incompbatible

Hye! It's giving error when I compare head[i] with "del". How would I dereference head[i] to be able to compare it with "del". I am bound to make head double pointer as a global variable . Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
node **head;
int main()
{
int del;
cout << "Enter size of array:" << endl;
			cin >> size;
			head = new node *[size];

..................further code to enter elements in this array............

cout << "Enter element to be deleted : ";
			cin >> del;
			for (int i = 0; i< size; i++)
			{
				if (head[i] == del) // ERROR operands type incompbatible
				{
del is an int.
head is a pointer to a pointer to node, so head[i] is a pointer to a node.
Comparing them makes no sense.

How can I say that, for example, the number "3" is the same as a pointer to a node? Makes no sense.

Is there perhaps some value inside a node object somewhere that you want to check the value of?
Last edited on
@Repeater
We dereferce a simple array by : cout <<array[i] ; and it will print the values

So why not head[i] will print the values? Yes, it is a pointer to a node! But how can I dereference the value of this array? I have to then delete a certain value which user wants by comparing it with "del"!
@seokiller I am also a big fan of sandeep sir!
Last edited on
There are two ways to dereference a pointer.

* and ->

In this case, -> would look nicer.

head[i] is a pointer to a node.

So head[i]-> dereferences that node.

So you could do something like:
if (head[i]->some_member_variable == del)
Topic archived. No new replies allowed.