What is the meaning of * at the beginning of the expression C?

Just a quick question for people who know a little c. What is the meaning of fo * at the beginning of an expression. how in...

If (this == thisThingOverHere)
ThisThing = *((WORD *) &Array[withThisPosition]);

You can assume that WORD is a 16-bit unsigned, and Array is an 8-bit byte. Its surprisingly hard to try to figure out what is going on here.

Greetings

+3
source share
7 answers

It’s not so difficult to figure out what’s going on. Let it break.


&Array[withThisPosition]

This says the address of the withThisPosition element is inside the array. Equivalent Array + withThisPosition.


(WORD *)

, , &Array[withThisPosition], WORD. "", , - Array .

:


*(...)

, . WORD .

, :


If (this == thisThingOverHere) {
  void *pointerToArrayELement;
  WORD *pointerToWORD;
  WORD result;

  pointerToArrayElement = &Array[withThisPosition];
  pointerToWORD = (WORD *)pointerToArrayElement;
  result = *pointerToWORD;

  ThisThing = result;
}
+8

.

:

#include <stdio.h>

int main(int argc, char **argv) { 
     int *i_ptr;
     int i, j;

     i = 5;
     i_ptr = &i;

     j = *i_ptr;

     printf("%d\n", j);
     return 0;
}

5

C ( "" ), . , "-", , *. , i_ptr integer (int *), i j . , "", (i j), (i_ptr) , .

& : &i i, i_ptr.

, , *, . *i_ptr , , i_ptr.

+6

this- > * (this).value, .

+2

C . - .

ptr , *ptr - , .

+1

, , .

&Array[withThisPosition]

withThisPosition Array. , : Array+withThisPosition.

(WORD *)

, , ( ), WORD.

*, - , .

, (withThisPosition) Array WORD ThisThing.

+1

* C , , . , .

* , , . , , (WORD *).

, * , . , , . , , . , , . , &Array[withThisPosition]) , Array - .

, , * C, , , .

Pointers gave me less headaches when I shared the two meanings *in my brain.

+1
source

You have missed parades in your expression. I assume you meant:

ThisThing = *((WORD *) &Array[withThisPosition]);

(WORD *) &Array[withThisPosition]

the part has a type pointer to WORD. The host * deletes the pointer. So

*((WORD *) &Array[withThisPosition])

has type WORD.

0
source

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


All Articles