Vlad
INT_MAX+1 is an obvious overflow
Anonymous
is -2 UINT_MAX - 1
Vlad
And it'll be INT_MIN
Anonymous
https://en.cppreference.com/w/cpp/container/vector
i know basic stuff but i'm recently seeing these "convoluted" ones
Anonymous
It initialized a vector of vector of ints with 1<< n elements where each internal individual vector<int> (I.e. the stored element) is initialized with n elements with value -1 each.
Anonymous
And it'll be INT_MIN
It will be Undefined Behavior. Signed int overflow is UB.
Anonymous
so i could have just done it like dp[1<<n][n] and assign -1 to them?
Yes. That is pretty much the array of arrays equivalent.
Anonymous
Yes. That is pretty much the array of arrays equivalent.
right lol would use this instead, short and crisp
Anonymous
anyway thanks, i understood it
Anonymous
right lol would use this instead, short and crisp
Though it works, remember that C++ doesnt support VLAs. So dont use these in your professional code. Should be ok on competitive programming sites.
Anonymous
Though it works, remember that C++ doesnt support VLAs. So dont use these in your professional code. Should be ok on competitive programming sites.
VLA means? Yeah like, it'd be OK for interviews too right? Although I am solving it currently for a problem, seemed OK
Anonymous
And it'll be INT_MIN
imagine int is 32 bits and loaded to a 64 bit register for processing (because the compiler finds it fast in that case or something), overflow happens (compiler assumes overflow never happens) and the final result is the lower 32 bits. you get 0 instead of INT_MIN even when your system uses 2's complement arithmetic edit: nvm example wrong, forgot 0 at MSB of 2's complement positive numbers
Vlad
It will be Undefined Behavior. Signed int overflow is UB.
If it's a literal it won't be UB
Vlad
If it's runtime value yes
Anonymous
If it's a literal it won't be UB
How will UINT_MAX - 1 be INT_MIN then?
Vlad
Why do think so?
Anonymous
It won't be lol
Because you said it under the post which asked if UINT_MAX-1 will be -2
Vlad
Because you said it under the post which asked if UINT_MAX-1 will be -2
It wasn't me. And you logic doesn't make sense
Anonymous
Vlad
INT_MAX+1 is an obvious overflow
Vlad
And it'll be INT_MIN
Vlad
Ya can't read
Anonymous
And it'll be INT_MIN
Learn how to reply. If you reply under a post without context people will assume that you are replying to the post above yours.
Pavel
If it's a literal it won't be UB
But can you guarantee that it won't be executed at runtime? Except constinit maybe
Vlad
Doesn't take a genius to figure out
Anonymous
I was continuing my own thought. It's one message apart
Yeah and people are supposed to use a crystal ball to figure your thought flow?
Anonymous
Doesn't take a genius to figure out
Ever heard of editing a message feature where you can add your thoughts if you think you missed out on something
Pavel
INT_MIN is a define
But INT_MAX + 1 is not
Vlad
INT_MIN is a define
So it'll be literal + literal
Vlad
Is 2 + 3 calculated at runtime?
Vlad
Probably not
Pavel
Is 2 + 3 calculated at runtime?
I'm not sure it can be guaranteed
Anonymous
And it'll be INT_MIN
Btw sorry to disappoint you. But INT_MAX + 1 is not guaranteed to be INT_MIN. So your flow of thoughts however genius you think of them to be, is still WRONG.
Vlad
Btw sorry to disappoint you. But INT_MAX + 1 is not guaranteed to be INT_MIN. So your flow of thoughts however genius you think of them to be, is still WRONG.
It's up to the compiler. C standard doesn't guarantee this. Although INT_MAX + 1 will be calculated at compile time due to it being a constant expression
Anonymous
i cant figure out how to call obj c from c
Anonymous
It's up to the compiler. C standard doesn't guarantee this. Although INT_MAX + 1 will be calculated at compile time due to it being a constant expression
So then your statement that it is INT_MIN is not correct then. Then your answer should have been "It is upto the implementation"
Anonymous
It's up to the compiler. C standard doesn't guarantee this. Although INT_MAX + 1 will be calculated at compile time due to it being a constant expression
Btw C standard says this is Undefined Behavior. It doesnt matter if it is computed at runtime or at compile time. The answer you get in either case is Undefined. Compilers do allow you to make this defined behavior by asking them to wrap around signed integer overflows like they do for unsigned integers.
Bruno
Looking for C internship. Do you know some opportunities?
Anonymous
n and dp are globally declared When I declare n=4 : int n = 4; int dp[1 << n][n] it throws me an error for dp when i do int dp[1 << 4][4], it runs well Why can't it access the n declared above it?
Anonymous
Try constexpr int n = 4;
yes it runs for const/ constexpr but what's the error signifying this: array bound is not an integer constant before ']' token int dp[1 << n][n]; When I am using only int n=4
Anonymous
Anonymous
https://github.com/mgood7123/Call-Swift-And-Objective-C-From-C i finally figured it out and created a repo that provides minimal examples of how to do so
Jerryjay
Anyone knows how to create a payload RHOST listener with c++?
Anonymous
is there an open source software license that allows for person to do anything with my code accept profit off it?
Anonymous
You mean "except"?
yes, sorry, it's bmy 3rd language
Diego
https://choosealicense.com/
Aura
Just a quick question. Is it better to use class or structure while implementing linked list?
Diego
honestly afaik the only real difference between a class and a structure is the default privacy setting
Diego
Which is usually ignored because it's good practice to override it anyway
Diego
So do whatever your heart tells you to do, this ain't C#
Aura
Yeah makes sense. Thanks man
Sandeep
void inorderFun(Node *root, vector <int> &res) { if (root == NULL)return; inorderFun(root->left, res); res.push_back (root->data); inorderFun(root->right, res); } vector <int> in Order(struct Node *root) { vector <int> res; inorderFun(root, res); return res; }
Sandeep
In this code..can't we just create a global vector<int> res
And do the same instead of creating two functions
Ravi
In base condition, you should return the res.
Sandeep
In base condition, you should return the res.
But how will I track back if root is null
Ravi
If root==null then return res.
Ravi
NULL*
Ravi
You are also suppose to put the if left child if right child condition fyi.
Ravi
Else it wont work
Sandeep
NULL*
But the return type is vector<int>
Ravi
res also is a vector int
Sandeep
Vector<int> inOrder .....is the function I'm supposed to write code in
Ravi
But the return type is vector<int>
i meant, if root == NULL then return res
Prajwal
I have doubt in my c question
Prajwal
Write a C program to enter id, name and address of 25 employees into structure variable called employee and sort them in ascending order on the basis of their name with use of pointer.
Prajwal
With use of pointer ??? What does it mean we have to use pointer as struct varaible ?