Comparison and assignment between pointer and integer C

I have a theoretical question about these two statements:

Assuming a ppointer to an Integer and aan integer:

a) if(p==a){.....}or if(p>a)..

b) p=a;

They are all illegal and bespecially dangerous, but how does the C standard treat them?

Reading the standard, I did not find whether they are errors, undefined behavior, undefined behavior, violation of restrictions, if one of them is legal or the other.

In countless similar questions, I did not find a solution.

+5
source share
4 answers

C11 (n1570) Β§6.5.8 [Relational operators] / 2:

Limitations

One of the following:

  • both operands are of real type; or
  • .

( , , char (Β§6.2.5/17))

Β§6.5.9 [ ]

:

  • ;
  • ;
  • , - void;
  • , - .

Β§6.5.16.1 [ ]/1:

:

  • , , righ - ;
  • , , ;
  • , ( , lvalue) , - , ;
  • , ( , lvalue), , - void, , , , ;
  • , , - ; , _Bool, - .

, .


? ? , . C , :

Β§4 []/2:

"" " ", , , undefined.

; Β§5.1.1.3 []/1:

(   ),    , undefined . .

( gcc), , .

,

:

   char i;
   int i;

, undefined, .

Β§6.7 []/3 , Constraint undefined.

, 3 - undefined , .

+4

. , , :

, , , 6.5.16.1, .

( 6.5.4, 3; 6.5.16.1 , void _Bool .)

, , . . uintptr_t .

+5

) ) . C99, & sect; 6.5.8, ; 6.5.9 & sect; 6.5.16.1.

0

, , . ), , : " ?". b) a, , , "a". :

p=&a

Now your pointer points to the memory address of integer a.

*p=a

The value your pointer points to is a.

p=a

Now your pointer points to the value of memory a.

Hope this helps!

-1
source

All Articles