When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
44 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@teal raptor
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. You can use !solved to close a post and mark it as solved.
char a[2] = "0";
*a = '1';```
this sets a[0] to 1 ... how would i set the next index in this way
a[i] = x;
btw " is string use ' for char
*a goes to the first index of the array
yeah
but if you have int arr[3]; you have to increment with sizeof(int)
I see
*a + sizeof(char) = '4';
error: lvalue required as left operand of assignment
;compile
#include <cstdio>
int main(void) {
int arr[10] = {0, 69};
printf("%d %d\n", arr[1], *(arr + 1));
*(arr + 1) = 50;
printf("%d %d\n", arr[1], *(arr + 1));
}
69 69
50 50
you dont have to write sizeof(char) because compiler do the thing for you, also you have to increment the pointer before
it increments the address with sizeof the elements
yeah but dont write the sizeof
Message is already solved
;compile
#include <cstdio>
int main(void) {
int arr[10];
printf("%p %p\n", arr+0, arr+1);
}
0x7fff64ecde70 0x7fff64ecde74
this works the same way but the compiler offsets the pointer only by 1
int arr[10] = {0, 69};
printf("%d\n", *((char*)arr + sizeof(*arr)));

because i typecast it to char array and char have size 1 byte
;compile
#include <cstdio>
int main() {
int arr[10] = {0, 69};
printf("%d\n", *((char*)arr + sizeof(*arr)));
return 0;
}
69
typecast dont cost any computational time