+ 2

Is the first character of a string also its address?

String

4th Sep 2019, 1:50 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
9 Réponses
+ 2
The indexes of the array refer to the addresses if they are not dereferenced. Run this piece of code and you'll get it. char arr[] = "Hello"; for(int i = 0; i < 5; i++) printf("%x\n", arr + i);
4th Sep 2019, 2:26 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
no
4th Sep 2019, 1:51 PM
Brave Tea
Brave Tea - avatar
+ 1
if the answer is no, what does the address of a string indicate?
4th Sep 2019, 1:59 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
+ 1
where the string is stored in memory
4th Sep 2019, 2:21 PM
Brave Tea
Brave Tea - avatar
+ 1
So is the first character? Or the index is signed in " \0 "?
4th Sep 2019, 2:33 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
0
Or maybe there are many byte who include index?
4th Sep 2019, 2:34 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
0
the * operator represents the bits other than the value bits, so the address in memory right?
4th Sep 2019, 2:48 PM
Ruggero Quaglia
Ruggero Quaglia - avatar
0
The name of the array, is a pointer to the first element. So if you don't dereference, you get the adress. *(a+3) or a[3] are just different ways of dereferencing. (That's my superficial interpretation that didn't trip me up so far and is hopefully correct enough. ;-))
4th Sep 2019, 3:12 PM
HonFu
HonFu - avatar
0
int main () {   int a [10];   float b [] = {0.12, 3.23, 1.23, 1e2, -12.43};   printf ("a has address =% x and occupies% d bytes n", & a, sizeof (a));   printf ("address of the first element =% x n", & (a [0]));   printf ("bytes occupied by each element =% d n", sizeof (a [1]));   return 0; }
4th Sep 2019, 3:36 PM
Ruggero Quaglia
Ruggero Quaglia - avatar