This question already has answers here:
C++: what does (a<<b) mean?
(8 answers)
What is 1 << 0?
(8 answers)
Closed 4 months ago.
I know this initialization: bitset<20>.
But what does this initialization mean: bitset<1<<20>?
But what this initialization means?
Parsing headache for the compiler perhaps.
You can use equivalent snippets: bitset< 1<<20 > - i.e. 1 left-shifted by 20 bits - bitset<1048576>
Related
This question already has answers here:
Why does pow(n,2) return 24 when n=5, with my compiler and OS?
(4 answers)
return value of pow() gets rounded down if assigned to an integer
(4 answers)
Is floating point math broken?
(31 answers)
Strange behaviour of the pow function
(5 answers)
Closed 6 months ago.
So in code i need to check wheather a no is perfect square or not ,
bool issquare(int x){
int root=(int)pow(x,0.5);
int y=pow(root,2);
if(y==x){
return true;
}
return false;
}
Now,
issquare(25);
is returning false. I tried debugging and this is weird,
root:5
x:25
y:24
why is y=24?.
This question already has answers here:
How to solve the 32-byte-alignment issue for AVX load/store operations?
(3 answers)
aligned_malloc() vs alignas() for Constant Buffers
(1 answer)
How to align std::array contained data?
(1 answer)
C++ alignment and arrays
(1 answer)
Where can I use alignas() in C++11?
(4 answers)
Closed 2 years ago.
512 intrinsic I need to align memory to a 64 byte boundary in c or c++ guide
I can do that with char *ptr = aligned_alloc(64, size); aligned_alloc
But i want to do something like char ptr[size] = {0}; aligned to a block
This question already has answers here:
How does C++ handle &&? (Short-circuit evaluation) [duplicate]
(7 answers)
Is short-circuiting logical operators mandated? And evaluation order?
(7 answers)
Closed 2 years ago.
In the below example will the comparison between a and c be executed or will it be skipped? I would assume the answer is no because the value of valid has already been determined since if any comparison is false in this expression the resulting value of valid is false, but I don't actually know if that's true.
int i = 10, b = 20, c, 30;
bool valid = (i > b && a < c);
Thanks for taking the time to answer my question!
This question already has answers here:
C++ cast syntax styles
(10 answers)
What is the difference between C-like casting and functional casting? [duplicate]
(4 answers)
Closed 3 years ago.
Suppose I have a floating point number x and I want to convert it into an integer. Is there any difference between int(x) and (int)x in C++.
I am new to C++ coming from Python background and naturally I tried int(x) to convert x to an integer but reading about C++ I came across type-casting i.e. (int)x and in this case it also works.
I was wondering what's the difference between these two approaches and in a wider context which one to use where?
float x = 5.5;
cout<<int(x)<<endl; //outputs 5
cout<<(int)x<<endl; //outputs 5
This question already has answers here:
C/C++: Pointer Arithmetic
(7 answers)
Closed 6 years ago.
Consider the code:
int arr[20]{};
int * ptr1=arr, * ptr2=&arr[1];
std::cout<<ptr1<<std::endl<<ptr2<<std::endl<<ptr2-ptr1;
Output:
0x7fff4003e0d0
0x7fff4003e0d4
1
Why it isn't 4 instead?
If it didn't to that you'd just end up dividing the difference by sizeof(whatever) all the time. The number of elements is far more useful than the raw difference. When you need the latter, cast the two pointers to char* for the subtraction.