Can you kindly explain this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you kindly explain this code?

I was trying to make this code for a long time and.. I made it.. but I don't understand one thing.. Variable x is unused.. so if I remove this, code acts differently.. https://code.sololearn.com/cUJAx5fUpft0/?ref=app

1st May 2021, 2:17 AM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
1 Answer
+ 1
HeyMohammad Mehedi Hasan 1.you doesn't use the value of x , so gives warning 2. how you are accessed array[3]'s value it is undefined This will help you 👇 #include <iostream> using namespace std; int main() { int arr[3] = {1,2,3}; int x; for (int i=0; i<3; i++) { x = arr[0]; for (int j=0; j<3; j++) { if(j==2) arr[j]=x; else {arr[j] = arr[j+1];} cout<<arr[j]; } } return 0; }
1st May 2021, 3:05 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar