Tell error in my code

Kindly tell the error in my code as if i dry run it is correct i am not able to find the error in my code.
my code :

Hello @Ramitgoel,

Before getting into the logic of your code.
Can explain me the following code segment?

string arr[n][100];
for(i=0;i<n;i++)
{
cin>>arr[i][100];
}

What should be the output of arr[0][0] as per your understanding of this array?


new code
@S18ML0016

Hey @Ramitgoel,

You have declared i as a global variable which is causing the issue.
While the second comparison of bat and batman, the value of i modifies to a value greater than n.

This is causing incorrect execution of your program.

Solution:
make i local to main and function separately.

Modified Code:
https://ide.codingblocks.com/s/164082

NOTE:
Your code is an example to illustrate why java does not support global variables.
As, these variables causes conflicts while combining two separate segments of code together.(During integration)

Hope, this would help.
Give alike if you are satisfied.

1 Like