In programming books, I noticed that "a variable of type int," and "a variable of an int type" are often used interchangeably. Which one is the correct one?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
As "int" is not a normal English word, it is difficult to say exactly how to use it correctly in a sentence.
So short answer: Both are readily understood and arguably valid.
I think most programming books say "of type int".
If you try to parse it, I think "type" is the noun and "int" is an adjective specifying what kind of type. So given the rule that in English adjectives normally precede the noun they modify, the "correct" version would be "of int type".
On the other hand, the writer may be thinking of "int" as a noun. In that case we have a construction like, "She went by the name 'Sally'". I'm not sure what the rule is there, but you wouldn't say, "She went by the 'Sally' name".
It would also be legal and conventional to say "The variable has a type of int".
int is not an English word. int is a type name in many programming languages derived from the word integer. So you can't say a variable of int type. But you can say
But this could mean int, long, short etc.
Similarly, you can say, a variable of type bool, or you can say a variable of boolean type.
This is not standard English, but rather technical computer science speech.
Many programming languages have variable types organized into several classes. For instance, there may be types
As a professional programmer, I would expect people to say "a variable of type int" or, more commonly, simply "an int".
If I heard someone say "a variable of an int type," I would think that person or book was not actually a programmer themselves, but merely a tech writer not "fluent" in talking about programming details.
FWIW, Google Ngram Viewer agrees that "an int" is the way to go:
Without the context the answers will be speculative or just a "guessing game". Anyway, int is the abbreviated form of noun "integer", which means "whole number" as such 1,2,3, -4,-5.
Having said that, the "type" in "a variable of type int" has nothing to do with "int". Check the excerpt below:
"These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber".
The writer wants to say "declare variable type as integer and variable type as float"
On the other hand, as John Lawler points out, in some programming languages these variable/data types may be subtyped into more categories according to their properties - as such "small int", "signed int", "unsigned int", "tiny int" e.t.c, which are integer types
Some computer programming languages have a whole family of