Category : variable-length-array

1. Code #include<iostream> int main() { int a=3; int *p=new int[a]; } Compilation result NO error compiles fine 2. Code #include<iostream> int main() { int a=3; int (*p)[2]=new int[a][2]; } Compilation result NO error compiles fine 3. Code #include<iostream> int main() { int a=3,b=2; int (*p)[b]=new int[a][b]; } Compilation result Error: Array size in new-expression ..

Read more

https://www.hackerrank.com/challenges/variable-sized-arrays/problem This is the problem statement. I tried the following code #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int n,q; cin>>n>>q; int n1; int A[n][1000000]; for(int i =0; i<n; i++) { cin>>n1; for(int j=0; j<n1; j++){ int c; cin>>c; A[i][j] = c; } } int a,b; ..

Read more

Anyways so here is the code int n; cin >> n; vector <int> a[n]; I’m using "using namespace std;" btw. Also, I’m, getting the error "’>>’: result of expression not used" which I think is the biggest culprit for my code not working. Anyways thanks in advance. Source: Windows Que..

Read more

i want to make function in c++ called ‘losowanie’, this function should random n numbers between 0-n. When i call this function, then i get : error: incompatible types in assignment of ‘int’ to ‘int [n]’ Here is my code : #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int losowanie (int tab[], int ..

Read more

I have initialized an array like this array[n][k+1]={0} where n and k are user input. But I found that it doesn’t initialize all index values to zero. While on the other hand memset(array,0,sizeof(array)) works fine. So why this happened? Because each time I initialised like this array[n][n]={0}, it always works fine. But why not in ..

Read more