Most voted "variable-declaration" questions
The declaration of a variable occurs when a variable is created.
Learn more…129 questions
Sort by count of
-
78
votes6
answers24661
viewsWhat is the difference between declaring variables using Let and var?
Since the word was introduced let in the Ecmascript I have only heard about it, so far I have not seen any practical example and to be honest I do not know very well what is a variable let and how…
-
65
votes3
answers5311
viewsWhen to use var in C#?
In C#, local variables in the scope of a method can be declared with implicit type using var, and type is solved at compile time: var i = 10; // implicitly typed int i = 10; // explicitly typed…
-
48
votes6
answers18641
viewsWhat is the difference between declaring an array with "array()" and "[]" in Javascript?
In Javascript we can declare an array in two ways: var matriz = new Array(); and var matriz = []; What is the difference between the two and what the consequences are? This question is being asked…
-
43
votes7
answers3681
viewsWhat are the implications of not declaring variables in PHP?
In php I can do this without declaring/defining variables: echo($foo); //resolve: vazio, sem nada $foo++; echo($foo); // resolve: 1 Using var_dump() the same gives, respectively NULL and 1. If I use…
-
38
votes3
answers96047
viewsWhat is the use of a static or final variable in java?
What is the difference of the declaration private static int var_nome for private final int var_nome for private int var_nome? How these statements can influence my algorithm?…
-
38
votes2
answers2688
viewsWhy do you usually declare a variable with default value?
In several applications that have been written with strongly typed languages, a variable (usually) is declared with its default value. Example: int x = 0; double y = 0; However, it is possible to…
c# variables characteristic-language typing variable-declarationasked 7 years, 5 months ago UzumakiArtanis 9,534 -
20
votes1
answer4057
viewsWhat is the difference between statement and definition?
These things seem to be the same thing. Are they? And assignment is different? The terms are interchangeable.
function terminology language-independent variable-declarationasked 8 years, 6 months ago Maniero 444,682 -
17
votes2
answers1267
viewsWhat is the difference between String[] args and String args[]?
What is the difference between the statements String[] args and String args[] in Java?
-
15
votes2
answers1034
viewsWhy does the absence of the suffix L cause the long variable to be interpreted as int?
When I use a short number for long, as long long1 = 9797;, the number is accepted even without using the suffix L. However, by placing a higher number - as its minimum and maximum values, for…
-
13
votes2
answers6067
viewsWhat’s the difference in instantiating, initializing, and declaring a variable?
Many articles on the Internet refer to these verbs, regardless of the programming language. But sometimes they are all confused or exchanged, which creates a lot of confusion. Which means…
variables terminology variable-declaration language-independent initializationasked 7 years, 10 months ago vinibrsl 19,711 -
12
votes1
answer1550
viewsWhy can’t you declare a variable within a case?
Why don’t you compile? #include <stdio.h> int main(void) { int valor = 0; scanf("%d", &valor); switch (valor) { case 0: int variavel = 1; printf("%d", variavel); break; default: int…
-
11
votes2
answers2240
viewsHow does C99 work in relation to C90 for declaring variables in the middle of the code?
At C90 and C89 we have to loop for must have its variable declared earlier at the beginning of the function scope, example: void main (void) { int i; for(i = 0; i < 10; i++) { /* Qualquer coisa…
-
11
votes3
answers935
viewsWhy does Javascript allow using variables without declaring?
I was doing a test on Jsfiddle, with the code below. In it I did not declare the variable i, but still, I can use it normally. Is that intentional or is it a flaw? So, I can just go out using…
-
11
votes1
answer112
viewsDoes creating local variables all the time generate extra cost for the software?
I made a program of which he writes variables all the time, and with that generated me a doubt, instantiating a variable all the time generates more cost than just assigning the value to an existing…
-
9
votes4
answers1531
viewsHow to assign a value to an Enum with binary notation?
To work with hexadecimal numbers, just add 0x in front of the number, this way: var numeroHexa = 0xff1120; The same goes for octal numbers, adding the 0: var numeroOct = 037; But how do you declare…
-
9
votes1
answer542
viewsWhy do we use parentheses in a pointer statement?
What is the difference between these two statements? int* array1[10]; int (*array2)[10]; Why are there parentheses in the second?
-
9
votes1
answer90
viewsWhy are there two const in the variable statement?
I can do it: const int* const objeto = &x; Why are there two const? What is the function of each?
-
8
votes6
answers7569
viewsUse of global variables and class variables in Delphi
I have some questions regarding the use of global variables and class variables using class var at Delphi. Declaring class variables with class var. unit Unit1; interface type TClass = class public…
-
8
votes2
answers1999
viewsWhy can’t I declare a variable with a numeric before the name?
I’m curious to know why I can’t create variables with a number before the name. I did some tests in Javascript, Actionscript and C#. var 4teste:String = "teste"; //ActionScript, erro! var 4teste =…
-
8
votes2
answers1281
viewsGood practices in declaring variables in a for
I’ve been making use of Resharper lately and I’ve enjoyed the experience of using it, but something’s been puzzling me. At times he suggests that certain variables be declared within some scopes, as…
-
8
votes1
answer80
viewsCan you initialize only a few members of a C array already in your definition?
I know you can do this: int a[5] = { 0, 3, 8, 0, 5 }; or int a[5]; a[1] = 3; a[2] = 8; a[4] = 5; Can you do the same in just one line, already in the definition? IE, you can initialize only a few…
-
8
votes2
answers308
viewsWhy does Kotlin use a way of declaring functions and variables other than "traditional"?
Traditionally the return type and variable type are indicated at the beginning, before the name: public int soma(int a, int b){ return a + b; } In Kotlin he is named after: fun sum(a: Int, b: Int):…
function characteristic-language kotlin variable-declarationasked 7 years, 4 months ago ramaral 44,197 -
8
votes4
answers711
viewsWhy are literal objects declared with const in Javascript currently?
Because of Ecmascript 6 I see examples that declare literal objects with the reserved word const. Code example: // Versão utilizada atualmente const obj = { x: 'example' }; // Versão utilizada…
-
7
votes2
answers3368
viewsMultiple variable declaration in Javascript
It has become quite common to declare variables in multiple lines in Javascript. Especially when they are initialized later: var var1 = null, var2 = null, var3 = 0; The "normal" would be like this:…
-
7
votes3
answers403
viewsBest practices in Javascript variable declaration
In the MDN Variables section we have the following statement: For that Reason, it is Recommended to Always declare variables at the top of their Scope (the top of global code and the top of Function…
-
7
votes3
answers189
viewsGlobal and local scope variable
If I print the global scope variable within a local scope, I am not allowed to redeclare again in the local scope. Why? For example, if I do: let a = 2; { let a = 3; console.log(a) //aqui aparece 3…
-
6
votes1
answer90
viewsHow is it correct to declare a variable that is a pointer?
I see some people do int* variavel; And some people do int *variavel; What is right?
-
6
votes1
answer84
viewsHow to start a variable correctly?
There is a difference between these two ways to start a variable? List<classeterapeutica> itens = new List<classeterapeutica>(); modelOff.classeterapeuticas.ToList(); or…
-
6
votes2
answers602
viewsDifference in C/C++ array declarations
What is the difference and impact that each of these 3 vector statements bring to my code? int n; cin >> n; int* arr = new int[n]; int n; cin >> n; int arr[n]; int n; cin >> n;…
-
6
votes2
answers229
viewsArraylist statement with type or without
I’d like to know the difference in declaring a ArrayList in this way: List<BancoPerguntas> listaBancoPerguntas = new ArrayList<BancoPerguntas>(); List<BancoPerguntas>…
-
5
votes2
answers5592
viewsVariable Static and #define
What is the difference between defining a variable static and use the #define in C? Apparently the two have the same function, right?
-
5
votes1
answer79
viewsType modifier: Type modifier
The type modifier register I have instructed the compiler to store the variable directly in the registers, however I do not see much its use in codes, this put, I have the following doubts: In what…
-
5
votes2
answers146
viewsDeclaration of `var as object field
How could I declare a variable var public so that it could take the return of the data. How would the statement of these variables without completion: var tbuscar = ?; var retorno = ?; public bool…
-
5
votes1
answer425
viewsWhat is Hoisting’s utility in Javascript?
Before ES6, all variables of a function are created independent of JS scope. That is to say: if(false) { var mensagem = "Olá!"; // declaração + atribuição } console.log(mensagem); => undefined…
-
5
votes2
answers106
viewsDifferences between variable statements in C#
What is the difference between these statements: Classex xx = new Classex(); var xx = new Classex(); Classex xx; If in the end I can use everything in the same way (methods, properties...) Ex.: I…
-
5
votes2
answers449
viewsQuestions about block scope in Javascript
The doubts are as follows: What is the difference between block scope and function scope in Javascript? The idea of block scope arose in Ecmascript 6 with let and const?…
-
4
votes1
answer1081
viewsDeclaration of key variables in Javascript
I recently saw a type of Javascript code, in some examples of Electron, which I believe is part of ES6. These are variable statements in the following format: const electron = require('electron');…
-
4
votes1
answer337
viewsHow to declare an integer type variable in C#?
I’m learning C# to migrate a system in VBA to C#. I’m really enjoying the language . NET. How do I declare an integer type variable?
-
4
votes2
answers1267
viewsVariable declaration before the main() function and after the main() function in C
What is the difference between declaring any variable (in this case number) before function main()? int number = 0; int main() { printf(" The number is %d\n", number); return (0); } and after it.…
-
4
votes1
answer107
viewsIs there still reason to use var in Javascript?
ES6 introduced the Keywords let and const for variable declaration. There is still reason to use var? If yes, in which scenarios to use?
-
4
votes2
answers353
viewsWhy does Typescript when compiled convert "Let" to "var" in variables?
If let variavel = "valor"; is also compatible with JavaScript, because in the compilation of Typescript, it turns to var variavel = "valor"? Take the test right here: function foo(){ var x = 1; let…
javascript typescript ecmascript-6 variable-declarationasked 6 years, 4 months ago Ivan Ferrer 12,096 -
4
votes3
answers158
viewsDeclaration of Java variables
Is there any difference between the two statements: First: int a; int b; Second: int a, b; Which is the best? Are the variables closer in memory or is that just a myth? Is there any significant…
-
4
votes2
answers234
viewsVariable declaration assignment in C
Is it necessary to assign a value to a variable in C once we declare it? I ask because an old programmer told me that it is necessary, because, if we do not declare at first, the compiler could…
-
4
votes2
answers182
viewscan I declare a variable in javascript so $variable?
I can declare a variable in javascript this way $variável ? If not. What would this syntax be ?
-
3
votes2
answers117
viewsUse multiple names with distinct functions in a variable
See these variable statements: var level = 0; var atual_sequence = 0; I could put them together like this?: var level, atual_sequence = 0; One would affect the functionality of the other?…
-
3
votes1
answer124
viewsDeclare variables at or near the top of where they are used?
Is it better to declare all the variables right at the beginning of the file, even if they only come to be used, I don’t know, a thousand lines later? Or better go declaring as the program evolves?…
-
3
votes2
answers5064
viewsHow to use the name of a cell of the Excel spreadsheet in VBA, not to indicate row and column?
How to use the name of a cell of the Excel spreadsheet in VBA, not to indicate row and column? For example, I named "Client Name" to cell B20, when I use this name in VBA to put in label (…
-
3
votes1
answer128
viewsWhy can’t I modify the string this way?
When we have a declared int variable, and then a pointer to that variable: int x = 10; int *p = &x; To modify the variable x through the pointer, we have to do: *p = 20; But when I declare: char…
-
3
votes1
answer193
viewsDifference between pointer vector for a class and vector for a class?
When is pointer to class will we have to allocate memory space? What is the difference between the following two statements and when they should be used ? Vector <class*> nameOfVector; Vector…
-
3
votes1
answer4789
viewsPass vector by reference or value?
I want to create two functions, one is to fill a vector with random numbers. The other function is to show the contents of the filled vector. So I did it this way: #include <stdio.h> #include…