can we create two variables of same name and of different datatype?

As you can see from the above reference, the same question can be answered differently for different languages.

In general, most modern programming languages do not permit the same name applied to different types because it would be confusing for the compiler.

There could be exceptions where scalars and arrays have different name spaces (e.g. Perl). Even then, the arrays have a prefix (@). So @name and name are different variables.

No, you cannot create two variables with the same name and different data types in the same scope. Each variable in a programming language needs to have a unique name within its scope. Having two variables with the same name but different data types would lead to ambiguity and make the code more difficult to understand and maintain.

However, if you are working with different scopes, such as different functions or different classes, you can create variables with the same name but different data types as they would be considered as separate entities.

No, we cannot create two variables of the same name and different data types in the same scope. In most programming languages, including popular ones like Java, C++, and Python, variable names must be unique within a given scope.

When you try to declare a second variable with the same name as an existing one, the compiler or interpreter will throw an error indicating that the variable name is already in use. This is because variable names act as identifiers and are used to refer to memory locations where the values are stored. Having two variables with the same name could lead to ambiguity and confusion.

If you want to use multiple variables with the same name but different data types, you would need to use different scope levels. For example, you can define variables with the same name in different functions or classes, but they will be different variables and cannot be accessed directly between scopes.