1.8k views

Which of the following statements is FALSE?

1. In statically typed languages, each variable in a program has a fixed type
2. In un-typed languages, values do not have any types
3. In dynamically typed languages, variables have no types
4. In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program

Answer is (C). In dynamically typed languages variables do have type- just that it is inferred during runtime.

edited by
0

comment on the main answer saying that "Almost. "This in practice means that you as the programmer must specify what type each variable is" is not true for statically typed languages with type inference, like Haskell, OCaml, "Perl 6", etc" @ http://stackoverflow.com/questions/1517582/what-is-the-difference-between-statically-typed-and-dynamically-typed-languages
..... does it make the option (A) false ??

0
That is not contradicting option A. "Having a type" and "inferring a type" are both different.
+2
even b should be incorrect?..as values have types variables do not ,in untyped languages isnt it?
0
In (D) option

In a program if we take a variable in two different type in two different function call , which kind of error it will generate?
+4

@srestha

Do you mean

int a = 10;
{
float a = 1.0;
}

This won't generate any error as 'a' inside and outside the block are different variables (just that name is same).

0
Could u pls explain what is statically typed , dynamically typed , no typed means ??
+20

A language is statically typed if the type of a variable is known at compile time. For some languages this means that you as the programmer must specify what type each variable is (e.g.: Java, C, C++); other languages offer some form of type inference, the capability of the type system to deduce the type of a variable (e.g.: OCaml, Haskell, Scala)

The main advantage here is that all kinds of checking can be done by the compiler, and therefore a lot of trivial bugs are caught at a very early stage.

A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc. This means that you as a programmer can write a little quicker because you do not have to specify types every time (unless using a statically-typed language with type inference). Example: Perl, Ruby, Python

0
nice... :)
+1
@sushmita

difference b/w type inference and dynamically typed language pls?
0
nice sushmita mam
0
0

@Arjun Isn't type casting makes option D false? Using type casting, variables can be associated with variables of different types.

+1 vote

Detailed explanation on geeksforgeeks

This is an ambiguous question. “Untyped language” has no standard well-formulated definition, thus answering this question would be a bit difficult.

(A) Statically typed languages have one type associated to a variable, which is fixed once it has been deduced. Though, types could either be specified while code editing by the coder (Eg. C, Java), or it can be inferred at compile time (Eg. C++11, Haskell). Hence, after compile-time, every variable is bound to one fixed type, making this statement [TRUE]

(B) According to one definition, un-type languages store values in form of bits, thus neither variables nor values have any types associated to them. Hence this statement becomes [TRUE]

(C) Dynamically typed languages deduce types of values and bind them to the variables storing those values. Hence, values sure have fixed types, but variables don’t have fixed types bound to them. Although we can say that binding a type to a variable according to values makes them typeful, but they don’t have one fixed type. This statement has some ambiguity. [TRUE/FALSE]

(D) Same reason as of (A) [TRUE]

Hence, correct answer should be (C)

–1 vote
0
what is type inferencing?

1
+1 vote
2
3
4
5
6