All Questions
27,305
questions
1
vote
2
answers
79
views
C++: array types and new
I'm learning C++. The following program looks nice and generic:
typedef some_type T;
int main() {
T* p = new T;
}
And it indeed works for non-array types like int, etc. However, if I try typedef ...
-1
votes
2
answers
50
views
C++ Rectangle 2D Array with numbers beside the rectangle
I've been trying to make a 2D array of rectangle, and i want the number of index x to printed beside the rectangle and index y to be printed below the rectangle..
Here is my code..
int height, width;
...
1
vote
1
answer
105
views
Arrays, Pointers and Memory addresses instances confusion in C++
I'm learning and playing a bit with pointers and memory addresses.
The thing is that I've tried doing some moves with instances inside arrays and getting their memory address, and I can't figure out ...
-2
votes
0
answers
53
views
Sum over arbitrary dimensions of an array fast in C++ with a GPU [closed]
I'm looking for a good (easy to write/debug) way to sum over an arbitrary dimension of an array in CPP using a GPU. I'm particularly interested in the case of summing over the 3rd dimension of a 3D ...
1
vote
2
answers
164
views
Smallest element after xor
Starting with array of N positive integers, support Q queries. Each query contains a positive integer i. To answer the query, replace each element of the array with the result of xoring it with i, ...
0
votes
0
answers
32
views
Calling methods from array of method pointers not executing [duplicate]
This doesn't execute any suggestions:
void (CClient::*pMethod[CNetwork::ClientEvent::E_CE_MAX_EVENTS])();
pMethod[CNetwork::ClientEvent::E_CE_ACCEPTED] = &CClient::Accepted;
pMethod[CNetwork::...
0
votes
0
answers
96
views
sizeof() operator in c++ displaying different results in case of arrays [duplicate]
Why is the result of the two array sizes are different?
#include <iostream>
using namespace std;
void fun(int a[]){
cout <<sizeof(a)/sizeof(int)<<" ";
cout<<...
-5
votes
1
answer
84
views
Union of two sorted arrays- GFG [closed]
vector<int> findUnion(int arr1[], int arr2[], int n, int m)
{
//Your code here
//return vector with correct order of elements
vector<int> temp;
int i=0;
...
-1
votes
0
answers
79
views
are consecutive objects created into a storage aliasable to a plain array?
Let say p is a pointer into a buffer of bytes, suitably aligned for objects of type T.
I'd like to build an array of T objects at p but I couldn't find a way to use placement new for arrays in a ...
-1
votes
2
answers
107
views
how do I connect two arrays and sort only one of them in c++? [duplicate]
So I'm new to C++ and doing that one Buzzy's exercise with pancakes. But I have absolutely no idea how to solve the last part of it:
Modify the program so that it outputs a list in order of number of ...
-1
votes
0
answers
32
views
What are the testcases that i had missed while writing this code in C++ in codechef?
Question)
Make Permutation
Chef has an array of size N. He wants to make a permutation using this array.
Find whether there exists an array B consisting of N non-negative integers, such that the array ...
-1
votes
0
answers
24
views
Issue with loop causing incorrect output in LeetCode problem 1509
I'm working on Leet Code problem 1509, where I need to find the minimum possible difference between the largest and smallest value in an array after performing at most three moves (each move consists ...
0
votes
1
answer
73
views
Segmentation Fault: Zsh: segmentation fault ./a.out
I am new to coding and am getting this error message when I run my c++ program:
zsh: segmentation fault ./a.out
Here's the code:
#include <iostream>
using namespace std;
int main(){
int i;...
1
vote
1
answer
50
views
Why are items showing up in a 2d array that I didn't add?
I am having a problem with my code.
When I add an element to a 2d array, it adds two instead. Here are some outputs to help explain the problem:
Blank game board:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 ...
2
votes
1
answer
80
views
Correctly deleting a dynamically allocated plain array, allocated with `std::align_val_t` alignment parameter
As an answer to Idiom for initializing an std::array using a generator function taking the index?, I proposed a way to obtain a properly aligned storage.
Yet I think that my solution can be simplified,...