GeeksforGeeks » C/C++ Programming Questions
what is the output ?? and why
(2 posts)-
int a[1],b[1];
a[0]=1;
b[0]=2;
b[1]=4;
int *num1;
num1 = &b[0];
a[1]= static_cast<int>(*(num1));
cout<<a[0]<<endl<<a[1]<<endl<<b[0]<<endl<<b[1]; -
Output seems to be unpredictable as the size of arrays is 1 and the code accesses a[1] and b[1]
#include<iostream> using namespace std; int main() { int a[1],b[1]; a[0]=1; b[0]=2; b[1]=4; int *num1; num1 = &b[0]; a[1]= static_cast<int>(*(num1)); cout<<a[0]<<endl<<a[1]<<endl<<b[0]<<endl<<b[1]; return 0; }
Reply
You must log in to post.