Int and ++ new increase by 2 every time

Just a silly question: I have a simple counter, but it seems to give a double value of what I expect.

short int *new = 0;
++new;
NSLog(@"Items: %hi", new);

And this returns:

Elements: 2

Relatively new to Cocoa, and still developing small details, like the clear form above ...

+3
source share
3 answers

You do not have an integer variable, you have a pointer ( , ). 2, . . , " ", "" - , . double 8 .

"*" . int,

short int new = 0;
++new;
+17

Aah, , , . , .

:

short int *new = 0;
NSLog(@"Items now: %hi", new);
++new;
NSLog(@"Items then: %hi", new);
+3

, new, , *new. , short int, 16- , . , 2.

I do not think that you are going to deal with memory cells. This is an odd definition of an integer, as well as the management of its location in memory, if only in specific situations. Code that will do what you want:

short int new = 0;
++new;
NSLog(@"Items: %hi", new);
+1
source

Source: https://habr.com/ru/post/1789767/


All Articles