Mat
Welcome!
Okai
MᏫᎻᎯᎷᎷᎬᎠ
If not
Mat
Well someone deleted it
Breaks the rule about english. He is allowed to advertise them
Mat
BUT that message up there is enough
MᏫᎻᎯᎷᎷᎬᎠ
I would sing a song in Arabic🤣
Vincenzo
hello, could someone explain me what i am doing wrong? '''#include <new> uint8_t *pArray; void setup() { pArray = new (std::nothrow) uint8_t[100]; if (pArray == nullptr) { //error } //delete[] pArray; } void loop() { add(); print(); delay(5000); } int8_t add() { uint8_t size = random(50, 99); for (uint8_t n = 0; n < size; n++) { uint8_t number = random(0, 255); *pArray++ = number; } return 1; } int8_t print() { for (uint8_t n = 0; n < 100; n++) { //*pArray++ } return 1; }'''
Vincenzo
Mat
At least format it as code
Mat
And tell us about the error
Mat
Runtime error? Compile error? Which one?
Mat
Have you read pinned message?
klimi
He haven't been rude
Mat
He haven't been rude
In fact no warns for him :)
klimi
Ye
Mat
He even can spread the word about it
klimi
klimi
We are not that cruel
Mat
Please @aster94ct, do a proper question :)
klimi
GN buddy
Mat
GN @KlimiCZ
klimi
Ty ty
klimi
I Will do some research to know when I should wake up
MᏫᎻᎯᎷᎷᎬᎠ
Guys GN
klimi
Hmmmm
klimi
It's nice tho to have this data
Vincenzo
so I am having some trouble with pointers, i would like to fill an array (with random data) and then print that array #include <new> uint8_t *pArray; int main(void) { pArray = new (std::nothrow) uint8_t[100]; if (pArray == nullptr) { //error } uint8_t size = random(50, 99); for (uint8_t n = 0; n < size; n++) { uint8_t number = random(0, 255); *pArray++ = number; } for (uint8_t n = 0; n < 100; n++) { //*pArray++ } //delete[] pArray; }
Vincenzo
the problem is that i can't fill the array and so i can't also print it
Mat
Why you're using *pArray++ instead of pArray[n]?
Mat
What's the error?
Mat
It gives you something or you arrive at the end with just a blank array?
Vincenzo
^
because it was the mistake i was looking for 😂
Vincenzo
#include <iostream> #include <new> uint8_t *pArray; int main(void) { pArray = new (std::nothrow) uint8_t[100]; if (pArray == nullptr) { //error } uint8_t size = 60; for (uint8_t n = 0; n < size; n++) { uint8_t number = 98; pArray[n] = number; } std::cout << "print\n"; for (uint8_t n = 0; n < size; n++) { std::cout << *pArray; } //delete[] pArray; }
Vincenzo
thanks!
Vincenzo
Why you're using *pArray++ instead of pArray[n]?
i get confused with pointer quite easy, i am still learning i thought that this *pArray++ = number; would have work honestly i am not sure why it is wrong 😅
Mat
blank array
What do you men by blank?
Mat
Filled with 0s?
Vincenzo
Filled with 0s?
it was filled by 254
Vincenzo
anyway now it works
Mat
First, using ++ overwrite the variable. You shouldn't (and i remembered you couldn't) use ++ with an array pointer
Mat
If a points to the head of an array, a++ will be equal to a = a + 1, thus losing where the head of the array is
Mat
I'd suggest you to try something like *(pArray + n)
Vincenzo
#include <iostream> #include <new> uint8_t *pArray; int main(void) { pArray = new (std::nothrow) uint8_t[100]; if (pArray == nullptr) { //error } uint8_t size = 60; for (uint8_t n = 0; n < size; n++) { uint8_t number = n; pArray[n] = number; } std::cout << "print\n"; for (uint8_t n = 0; n < size; n++) { std::cout << *(pArray+n); } //delete[] pArray; }should be correct
Mat
Now make it efficient
Mat
Using only a loop
Mat
You can even jump the array part, but i don't think it is the aim here
Vincenzo
Using only a loop
ahhh yes i know how to do everything inside a for but yes it's not the aim!
Mat
Okay :)
Mat
Good luck!
Anonymous
What is the difference in Char *string = Char string [] =
Anonymous
I know upper one is pointer And other is array
Anonymous
reading all the things u guys talking about making me scared like hell..can i make it possible to learn all those things in 3 years?😂
Mat
You only need patience, will and practice
Anonymous
What is the difference in Char *string = Char string [] =
The pointer will point to read-only memory in the top one, therefore you cannot modify that string, however you could change the pointer, if I am correct
Anonymous
pray for me😢
Ludovic 'Archivist'
What is the difference in Char *string = Char string [] =
None, they translate to the very same thing
Ludovic 'Archivist'
klimi
hi ludo
Anonymous
Both are pointers in the end
Yes, I thought one is modifiable while the other is not
olli
What is the difference in Char *string = Char string [] =
Since you have already written the assignment operator, I assume you're primarily interested in the following void foo() { char *p = "Hi"; // const char* in C++ char ar[] = "World"; } as @Just1nC already mentioned p points to the read only string literal. The string cannot/shall not be modified. Only the size of a pointer is reserved for p. ar is an array and reserves memory depending on the value assigned. The whole string is copied into this memory location. You may modify the content of ar as you please. ISO C++ forbids assigning a string literal to a non-const char pointer, instead you would need to write const char * ptr = "Hello World"; They behave the same when they are function parameters e.g. void foo(char ar[]) {} void bar(char * p) {}
Dima
what would one prefer: serialize simple int32 in data OR serialize header byte for uint8/16/32 and then read value by its size?
olli
what would one prefer: serialize simple int32 in data OR serialize header byte for uint8/16/32 and then read value by its size?
I think it depends. In general the second approach is more flexible and memory efficient. If you are likely to need the four bytes in most cases anyway and you can guarantee everything will fit in 4 bytes the benefits might vanish
Mr. M
Looking for someone who can help me programm a bot that works with SocialMedia. PM if interested and I can also pay you a little bit 😊
klimi
hmmmmmm
klimi
usually we discuss the programming or some problems here