C pointers vs. Objective-C pointers -


I am coming from Objective-C background and trying to increase my knowledge in C. One thing has confused me, though, and this is the difference between pointers in C and OBJ-C as you can see in the examples given below, things behave differently between the two languages, and I Wondering why you can explain this?

C code works fine:

  myFunction zero () {int x, * pointerX; PointerX = & amp; X; * Pointerx = 5; // print: "x5" printf ("x is:% i", x); }  

Obj-C code failed:

  - (zero) myMethod {NSString * string = @ "caramel coffee" , * String pointer; String pointer = & string; // Alert: Assign with incompatible indicator type * string pointers = @ "chocolate milkshake"; // Exception: The incompatible NSLog incompatible type (@ "string:% @", string); }  Question:  Why can not I put the string pointer in the string's memory address ( stringPointer = & amp; string; ), and I  * pointerX = 5; Why am I able to, but I can not execute  * stringPointer = @ "Chocolate milkshake";  Under Objective-C? 

I know that deals with objects and objects do not work, but I am unable to understand back-end details because of not working in the Objective-C. Any help is greatly appreciated. Thanks! In the first example, x and pointerX

( (int) and (int *) respectively). In your second example, there is same type ( NSString * ) in string and stringPointer . Try instead:

  NSString * string = @ "caramel coffee", ** string pointer;  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -