I know C and Java uses lexical scoping and the scope of a variable is within the block where it was defined. See the code of Java:
public class Main
{
public static void main(String[] args) {
int j = 0;
while(j==0){
int j =1;
System.out.println(j);
}
}
}
This program give an error "variable j is already defined in method main"
See the code in C:
#include <stdio.h>
int main()
{
int j = 0;
while(j==0){
int j =1;
printf("%d",j);
}
}
Here we get an infinite loop "11111111.............." As output.
Why does the C compiler not complain about the j variable as Java do?