C - What does it mean that both pointers are equal using '==' operator? -


I'm in someone who is studying a language

I'm curious for some The '==' parts of the operator

I know that the indicator is a variable that stores memory address but here comes a question. When I try to use the '==' operator, those two pointers are indicating different addresses, the '==' operator works.

Here's my code below

I want to know why the statement R == S is considered true and why R and S. gives me some 'ignorance value' which is 90 (my computer Should those values ​​be 56)?

  Add # & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Defined N10 zero addition (int *, int *, int *); Int * Add (int *, int *, int *); Int main () {int a [n], b [n], c [n]; Int m; Int * p; Int * q; Int * r; Int * s; Four * ptr1 = "ATGC"; Four * ptr2 = "TCGA"; Char * ptr3 = ptr1; Printf ("result from strncmp:% d \ n", strncmp (ptr1, ptr2,4)); If (strncmp (ptr1, ptr2,4) == 0) {printf ("strncmp operator works! They are both \ n"); } {{Printf ("strncmp operator does not work! They are not the same both \ n"); } Printf ("Ok another example here \ n"); If (ptr1 == ptr2) {printf ("ptr1 and ptr2 are identical \ n"); } And if (ptr1 == ptr3) {printf ("ptr1 and ptr3 are the same"); } Other {printf ("? \ N"); } Printf ("Compare prices after function call \ n"); For {m = 0; m & lt; n; m ++} {a [m] = m; B [M] = M * M; C [M] = 0; } Printf ("works as null function \ n"); Adding (A, B, C); Printf ("After function call \ n"); (M = 0; m and lt; n; m ++) {printf ("% d +% d =% d \ n", for a [m], b [m], c [m]); } P = & amp; C [N-1]; Q = & amp; C [N-1]; R = Add (A, B, C); S = Add (A, B, C); If (p == q) {printf ("those two pointers are equal to p and q \ n"); Printf ("indicator p's address 0x% p \ n", & amp; p); Printf ("indicator q's address is 0x% p \ n", & amp; q); Printf ("The value of the indicator p is% d \ n", * p); Printf ("indicator value is% d \ n", * q); } Other {printf ("they are differenct \ n"); } If (r == s) {printf ("those two pointers are equal to R and S \ n"); Printf ("indicator R's address is 0x% p \ n", & amp; r); Printf ("indicator's address is 0x% p \ n", & amp; nbsp;); Printf ("value of indicator r% d \ n", r); Printf ("indicator value is% d \ n", s); } Other {printf ("they are differenct \ n"); } Return 0; } Zero plus (int * a, int * b, int * c) {int i; For (i = 0; i  

You do not return anything from the add function Are there.

You found r ==s because both of the add were returned to all of the same irregularly / garbage value.

Actually, by returning a value from the function, saving the function's stack memory (and sometimes in the CPU regime R , some value is popped out) Is similar to

To avoid such mistakes, always enable the -wall option (at least) your ( GCC ) compiler, and Focus on every warning.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -