I have hard time understanding the following code buffer[i] = arr ? arr[i] : 0;.
Does this mean that if arr contain any thing then its equal to buffer[i] and if it doesn’t it equals to 0?
#include <iostream>
using namespace std;
int main ()
{
int arr[5]={11,22,33,44,55};
int * buffer;
buffer = new int [5];
for(int i=0;i<5;i++){
buffer[i] = arr ? arr[i] : 0;//true/falls
cout<<buffer[i]<<",";
}
cout<<endl;
int arr2[5]={};
int * buffer2;
buffer2 = new int [5];
for(int i=0;i<5;i++){
buffer2[i] = arr2 ? arr2[i] : 0;//true/falls
cout<<buffer2[i]<<",";
}
cout<<endl;
}
It seems the code may have been ported from when
arrwas allocated dynamically. Now it’s on the stack soarrcan never beNULLand so the check is useless