Anonymous
In most contexts array object decays to a pointer to first element
olli
I don't think it's a flaw iirc he did it to keep some sort of compatibility with B and BCPL
Anonymous
Anonymous
Endless loop
olli
and I like it, because how else would you define the behavior without posing restrictions on calling conventions?
I think it's not a bad solution.
Anonymous
Most of C++ design flaws are made just because it's tried to be compatible with C
Anonymous
olli
Anonymous
Wat
Anonymous
It's Undefined behavior
Deni
Ub
Anonymous
No
Anonymous
*pa gives you whole int, not a first byte
Anonymous
So you cannot write to pa + 1
Because it would be next int
Anonymous
Anonymous
Then probably it's ok
Anonymous
Useless, but ok
olli
the only thing to watch out for is endianess
olli
could be big or little endian, so your int depends on your arch
Ammar
It is machine dependent behavior. You will get different result on big endian machine and little endian machine.
This is well defined behavior.
Anonymous
olli
"like an array" is pretty vague, in the end both an array and int is a consecutive region of memory
Data is not an array but one might argue "it behaves like it"
void * Data = 0;
char *P = (char*)Data;
*P++ = 1;
*P++ = 2;
olli
you can read every byte of the memory pointed to by Data (the same way you did with int) but that doesn't make Data an array.
Ammar
"consecutive region"
Consider this example for little endian
int a = 0x01234567;
char *pa = (char *)&a;
Will be:
*pa++; // 0x67
*pa++; // 0x45
*pa++; // 0x23
*pa++; // 0x01
olli
by that logic, everything would be an array of char
Ammar
Yeah, I think memory works like a huge array and primitive data types are the number of bytes read in one cycle.
olli
speaking in terms of the language, no. But that's more or less how it works under the hood
olli
you cannot pass an array by value.
in theory it would be possible, but how would you do it? Who keeps track of the size? Who allocates the space? Who frees the space?
Ammar
Depends on the number of bytes. You can cast char[4] to (int32_t *). Take dereference, pass it as int32_t, then convert back to char[4] once it needs to be read by your function.
olli
yes, because there is no good solution and back then it was designed with compatibility to B/BCPL in mind
olli
you could always do something like this to "copy" the array.
typedef struct {
int Array[30];
} Dummy;
void Bar(Dummy D) {}
int main() {
Dummy D;
Bar(D);
}
Ammar
In 64 bit machine, you can only reads 8 bytes at a time.
Except for SSE and AVX cases (which can read more than 64 bit at a time).
Ishikawa
is there any way to make variables accessible to system() commands.
Ishikawa
...
you really shouldnt do that, but you could build the string using something like sprintf
Ishikawa
this outputs blank. i know this is expected but is there any way it can output 567?
Ishikawa
...
please illustrate
int x = 1234;
char buff[256];
sprintf(buff, "echo %d", x);
system(buff);
...
never never never ever pass user-input to system bad thing
Ishikawa
why is that?
Ishikawa
...
Ishikawa
Anonymous
This is not a assessment or test work.
I tried this but there are some errors.
If i give an input 5 it only showing Factorial 5 = 120
I need to get the Factorial from 1 to 5
How can i do that
Anonymous
Anonymous
Anonymous
/warn no one will write program for you
Anonymous
Is this AVL tree balanced??
Harsha [M]
Anonymous
ya
How to find if it's balanced or not?
Anonymous
Merazi
Matteo
/get cppbookguide
Mufasa🦁✨
Who can teach me c++?
Tassss
Anybody on insta?
max
Cut m and n letters from end of string, then find number of turns to get back original string
max
guys can you help
M.Khorram
Who can teach me c++?
possibly no one (sorry for that)
Learning a new programming language usually needs studying and exercise for a long period of time
M.Khorram
Anonymous
ya
hey wait, i think its imbalanced, i inserted 8,now comparing the total heights from 8 to root and the right child of the root, the difference in height is 2, i.e 3-1 = 2
Kenny
Kenny
If height > 1 or height < -1 -> imbalanced
Kenny
And you should balance it
Anonymous
I was asked to insert another 4 in the tree , but there's already a 4 there , then where do I have to insert the 4 that was asked to insert ...
Andrew
Andrew
sorry got wrong, you got to add under the 4
Andrew
cause is the nearest available space
Andrew
it depends on how the heap is defined
Andrew
https://stackoverflow.com/questions/22570126/can-max-min-heap-trees-contain-duplicate-values
Garvine
Hello
Who has an algorithm for generating match fixtures to share with me
Anonymous
Hello, Is this below correct?
void f(std::vector<thing> && t);
static_assert(passing the argument as reference):
std::vector<thing> foo;
void f(foo);
static_assert(also this passing the argument as reference):
void f(std::vector<thing>());
Ishikawa
what can i use instead of a " "?
V01D
V01D
char str[3] = {'H', 'I' /*null terminator inserted by compiler*/};
Ishikawa
does not work brother