#include int main() int b = 10; //assign the integer 10 to variable "b" int *a; //declare a guideline to an essence "a" a=(int *)&b; //Get the memory ar of change "b" actors it //to one int pointer and also assign it to reminder "a" int *c; //declare a pointer to an integer "c" c=(int *)&a; //Get the memory place of variable "a" which is //a guideline to "b". Actors that to an int tip //and entrust it to pointer "c". Printf("%d",(**c)); //ERROR wake up HERE. Return 0; Compiler to produce an error:

error: invalid type argument of ‘unary *’ (have ‘int’)Can someone define what this error means?


Answers


100
Since c is holding the deal with of an creature pointer, its type should be int**:

int **c;c = &a;The whole program becomes:

#include int main() int b=10; int *a; a=&b; int **c; c=&a; printf("%d",(**c)); //successfully prints 10 return 0;
Monday, august 9, 2021

*

answer 3 Months earlier
Heisenberg
25
Sydius outlined the types fairly well:

Normal pointers are simply that - they point to some point in memory somewhere. That owns it? just the comments will let you know. Who frees it? hopefully the owner at part point.

You are watching: Invalid type argument of ‘->’

Smart pointers room a ceiling term that cover countless types; I"ll i think you supposed scoped guideline which supplies the RAII pattern. That is a stack-allocated object the wraps a pointer; as soon as it goes out of scope, that calls delete top top the guideline it wraps. The "owns" the consisted of pointer in the it is in charge of deleteing it at some point. They enable you to acquire a raw referral to the tip they wrap because that passing to various other methods, and also releasing the pointer, allowing someone rather to own it. Copying them does not make sense.Shared pointers is a stack-allocated object that wraps a guideline so the you don"t need to know who owns it. Once the last shared pointer for an object in storage is destructed, the wrapped reminder will also be deleted.

How about when you need to use them? You will certainly either make heavy use of scoped pointers or common pointers. How plenty of threads are running in your application? If the answer is "potentially a lot", shared pointers deserve to turn out to be a performance bottleneck if offered everywhere. The factor being the creating/copying/destructing a shared pointer needs to be an atom operation, and this can hinder power if friend have numerous threads running. However, the won"t constantly be the instance - only experimentation will phone call you for sure.

There is an debate (that i like) versus shared needle - by utilizing them, girlfriend are allowing programmers to neglect who own a pointer. This deserve to lead to tricky instances with circular referrals (Java will certainly detect these, yet shared needle cannot) or basic programmer laziness in a huge code base.

There room two reasons to usage scoped pointers. The an initial is for an easy exception safety and also cleanup to work - if you desire to guarantee that an item is cleaned up no issue what in the challenge of exceptions, and also you don"t want to stack allocate that object, placed it in a scoped pointer. If the procedure is a success, you deserve to feel cost-free to move it end to a shared pointer, yet in the meantime conserve the overhead with a scoped pointer.

See more: Star Wars Saga Edition Threats Of The Galaxy Pdf, Saga Edition

The other case is once you want clear thing ownership. Part teams prefer this, some execute not. Because that instance, a data structure might return pointers to internal objects. Under a scoped pointer, it would return a raw pointer or referral that have to be treated together a weak recommendation - the is one error to accessibility that reminder after the data framework that owns it is destructed, and it is an error to delete it. Under a shared pointer, the owning object can"t destruct the interior data it reverted if someone still hold a take care of on that - this might leave resources open up for much longer than necessary, or much worse depending on the code.