M
Maxime Savard
Hi there,
What I'm trying to do is quite simple and in fact I have found a way to
do it but I am not sure if it is OK. What I mean is sometime in c++ stuff
can "work" but not be "correct". Here is my code maybe you'll see something
wrong :
char test[4] = {'1','2','3','4'};
char get = '0';
int add = (int)&test;
add++;
memcpy(&get, (void*)add, sizeof(char));
printf("Second char in array is : %c\n", get);
My objective here was to read the '2' in the test array without using
test[1] as the starting point to read. Then I discovered that when using
&test+1 as the starting address I was in fact increasing it by 4 (maybe it
is basic stuff here but I don't know why, I'm kinda newb). Then I came up
with this technique. The final question is... Is it "correct" ?
Thanks for any info!
Max.
P.s. Sorry for any typo I'm french
What I'm trying to do is quite simple and in fact I have found a way to
do it but I am not sure if it is OK. What I mean is sometime in c++ stuff
can "work" but not be "correct". Here is my code maybe you'll see something
wrong :
char test[4] = {'1','2','3','4'};
char get = '0';
int add = (int)&test;
add++;
memcpy(&get, (void*)add, sizeof(char));
printf("Second char in array is : %c\n", get);
My objective here was to read the '2' in the test array without using
test[1] as the starting point to read. Then I discovered that when using
&test+1 as the starting address I was in fact increasing it by 4 (maybe it
is basic stuff here but I don't know why, I'm kinda newb). Then I came up
with this technique. The final question is... Is it "correct" ?
Thanks for any info!
Max.
P.s. Sorry for any typo I'm french