Ludovic 'Archivist'
Probably you meant volatile ?
Yes, typing on a phone makes things complicated
Ludovic 'Archivist'
Ilya
It is on the same level of cleverness as volatile int f() { return 4; }
with this volative I don't understand what's the problem with this code.
Ilya
Ludovic 'Archivist'
What size information do you mean?
The fact that you store 2 integers and not one in that reference
Ludovic 'Archivist'
But you DONT store two. Just one
My bad on that, looked like square brackets to my tired self
Ilya
The fact that you store 2 integers and not one in that reference
You couldn't have assigned reference to an array to the reference to one int.
Ludovic 'Archivist'
Still a bad practice, one should rather use a unique_ptr
Ilya
Still a bad practice, one should rather use a unique_ptr
Well yes, but what if you program your own smart pointer, for example
Ludovic 'Archivist'
*new int[2] returns int&
Ludovic 'Archivist'
Ilya
You can with that syntax
No, you can't that would be type check error.
Ludovic 'Archivist'
Store a pointer
Ludovic 'Archivist'
No, you can't that would be type check error.
Explain me how int& is different from int& to the compiler
Ilya
*new int[2] returns int&
No, it returns reference to int array of two elements. int (&) [2]
Ludovic 'Archivist'
No, it returns reference to int array of two elements. int (&) [2]
Sorry to tell you but no, using deference operator on int* gives you int&
Ilya
Then don't use a reference?
So, until you want to use pointer arithmetic, there is no problem with this.
Ludovic 'Archivist'
So, until you want to use pointer arithmetic, there is no problem with this.
Except the fact you wrap something for no reason and may need to unwrap it later
Ludovic 'Archivist'
recheck
Confirmed
Ludovic 'Archivist'
Wrap in what ?
FYI, there is no requirement for how references are implemented in C++
Ludovic 'Archivist'
It is valid for references in a C++ implementation to be implemented as a class with side effects
Ludovic 'Archivist'
recheck
http://cpp.sh/5isfy
Ludovic 'Archivist'
It is valid for references in a C++ implementation to be implemented as a class with side effects
The C++ AM doesn't have any saying on how references are implemented. If references are mostly implemented as syntaxic sugar around of pointers in most implementations, it is not defined as such in the standard
~
Hi guys, I'd like to know if there are any advantages by using a pointer to function in a struct, used to create a linked list [C]. Thank you
~
In this way it seems an object-oriented way
~
What is this function used for?
Any behaviour, I would just know if it is useful
~
What is this function used for?
Perhaps on the list itself
Ilya
Any behaviour, I would just know if it is useful
This can't be answered, I cannot say if it is useful if I don't know use of it
~
This can't be answered, I cannot say if it is useful if I don't know use of it
Thank you for the answer. I'd just know generally if it could be useful in any way
~
Having a pointer to function into a struct
~
I know, it could be a weird question ahah
Ilya
Hi guys, I'd like to know if there are any advantages by using a pointer to function in a struct, used to create a linked list [C]. Thank you
You have a struct, it uses linked lists and needs to create linked lists, so for this the struct needs this pointer to function that creates list, is it?
Anonymous
Even add
~
My question was about if it will be able to do something useful, but as far as i can see, it's useless
Ilya
Thank you for the answer. I'd just know generally if it could be useful in any way
if you need this pointer then save it, if you don't need it or the function will be anyway same function, then it is not useful at all, you will be just spending memory for this.
~
Thank you again!
Javi
Thank you for the answer. I'd just know generally if it could be useful in any way
Pointers to functions are useful when you need to change the behaviour on runtime or if the behaviour is expected to change in the future but you don't want the rest of your code to rely on the current behaviour
Ares
Hi
Anonymous
thank you hi too
Muslim
Ok I’m so sorry
Dima
#ot
Anonymous
Ok
Gaiya🇱🇰
🧐
Anonymous
🧐
Any question
Gaiya🇱🇰
Any question
Nope bro.. Thanks
Anonymous
Ok
Gaiya🇱🇰
😊👍
Shubh
Hello
Shubh
😀
Charles
Ok
rex
int getSum(int r1, int r2, int c1, int c2, int dp[N + 1][N + 1]) { return dp[r2][c2] - dp[r2][c1] - dp[r1][c2] + dp[r1][c1]; } bool sumFound(int K, int S, int grid[N][N]) { int dp[N + 1][N + 1]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + grid[i][j]; for (int i = 0; i < N; i += K) for (int j = 0; j < N; j += K) { int sum = getSum(i, i + K, j, j + K, dp); if (sum == S) return true; } return false; } int main() { int grid[N][N] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; int K = 2; int S = 14; if (sumFound(K, S, grid)) cout << "Yes" << endl; else cout << "No" << endl; }
rex
can anybody help me to understand the sumfound() part
rex
how sum goes to dp[] matrix
rex
4
Talula
4
The program doesn't even work... it tries to write to dp[4,4] using dp which isn't defined so your answer is wrong.
Talula
If you initialize dp first after it's defined it might just make sense.
rex
but as i copied this from popularsite so may be there is some is fault in my understanding
rex
so i post it here
rex
after researching i found that it follows kadanes algorithhm
rex
may be any of know post it here
rex
you
Talula
Sorry I'm not on PC right now, will send you the part of correction when I get to my computer.
Talula
Guys... can someone help rex with double dimension array in C++?
Ilya
http://cpp.sh/5isfy
Hi you were correct, new expression decays arrays to pointer, fuck! I'm disappointed. BUT this is not related to the code snippet, actually, because there was no arrays originally and both pointers and references would starve from array to pointer decay similarly.
Ilya
can anybody help me to understand the sumfound() part
What can we help you with? This program is invalid, and you must show all the code for it to be understandable.
Ilya
can anybody help me to understand the sumfound() part
Multi-dimensional arrays cannot be handled like this AFAIR.
Anonymous
guys if I do a 1 / 1.1 division it gives me 1, why?
MilkBeforeCereal
show the code
Anonymous
https://pastebin.com/fFQ1mSaq