Most voted "variables" questions
A variable is a named data storage location in memory. Using variables , a computer program can store text numbers, binary data, or a combination of any of these data types. They can be transferred in code, to other functions and even other applications.
Learn more…645 questions
Sort by count of
-
5
votes1
answer415
viewsTemporary variable performance within loop
During college a professor commented with me that declare a variable before a loop and reuse it was an economic and more interesting way to do it. For example (in Java): String str; for(Pessoa p :…
-
5
votes5
answers11566
viewsHow to find the type of a variable given by the user?
I would like to ask the user to type something and find out what kind of what he wrote. So far I only know the input(), but the input() only returns the type String. If I put int(input()) or…
-
5
votes2
answers419
viewsIs it possible to instantiate a class without storing it in a variable?
Normally I do so: $a = new MinhaClass($Parametro); You can do this without creating the variable $a ? Only with the new?
-
5
votes2
answers134
viewsWhat is the problem of returning a local variable?
What can happen if I return a local variable? I read on the internet that it is not a good idea to return a local variable. Maybe why the variable when exiting the function is deleted? Example:…
-
5
votes1
answer149
viewsConfigure HTML variable inside Nodemailer html
I need to send an email using Nodemailer, and I need to send email with html, but I’m not able to set the variables directly inside the email HTML, I’ve tried the replace() and did not succeed.…
-
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
answers1116
viewsWhat are the scopes of the variables in the ADVPL and when to use each one?
I am taking a code from a colleague to give maintenance. I find myself with this code here: Static Function Conv2Json(cCpo) Local cRet := "" Local cSeparador := "" aCpo := StrtoKArr(cCpo, ';')…
-
5
votes1
answer142
viewsWhy do local variables not receive default values from the Java compiler or JVM?
Why the compiler assigns values default for attributes but not for local variables? public class Teste{ int a; public void metodo() { int b; System.out.println(a); System.out.println(b); } }…
-
5
votes1
answer5532
viewsIn a file . bat (Batch) how to rename a file using variables such as %userprofile%?
I am wanting to rename a file that is found on the Desktop using batch script. The only line that’s going wrong is this: rename "%userprofile%\Desktop\Lista.xlsb" "%userprofile%\Desktop\Lista -…
-
5
votes2
answers62
viewsIs there a method of merging equal items into a var list in LINQ in C#?
Hello, good morning, good afternoon or good night, all right? I have a method that obtains products from a database using LINQ in C#, but on that list there are products that are repeated, so you…
-
5
votes1
answer143
viewsWhy are instance variables usually initialized in the constructor?
I have seen several codes where the instance variables of a class are initialized in the constructor, even I do it myself by watching others do it. But I never understood it. Logical that has the…
-
5
votes1
answer104
viewsIs it recommended to explain all variables?
This is a question as to the readability of the code or if there is any style pattern as to this. Well, the Zen of Python tells us that Explicit is Better than implicit. but how to interpret this?…
-
4
votes2
answers2140
viewsHow to "clean" static variables?
In C++ static variables are very important. Let’s assume that I want to make a factorial that uses recursion. unsigned long long int RecursionFatorial(unsigned int fator) { static long long int…
-
4
votes2
answers515
viewsphp Show the variable
I have a page that sends emails when one of my form dates is ending. Currently he only sends the name of the person who has the date to finish but I want him to inform the date that is at the end.…
-
4
votes3
answers3392
viewsHow to use static and global variables in PHP?
I need the value of a variable in several functions to increment and decrement the value of the variable. I have tried using static variable started with null value, but even changing its value, it…
-
4
votes1
answer216
viewsHow does the reference to undeclared variables work in PHP?
In PHP, according to the manual, the reference of one variable serves for a variable to point to the same place where the other is in memory. I also saw that when we declare references to a variable…
-
4
votes3
answers10588
viewsGlobal variable in all functions of the class
Usually when I want to pull a variable that is out of class, I use global $variavel, but wanted this variable to be accessible in all functions of the class, not to be needing to "pull" in all…
-
4
votes3
answers346
viewsVariable error within the function
I’m having problems and for what I searched in the internet forums, others have the same doubt that I. I cannot use PHP variables within the transaction function. How do I set a variable? For…
-
4
votes1
answer3054
viewsHow to use Windows variables in Delphi?
Hello, I’m creating a project on Delphi, However, it needs to create some files, it wouldn’t give a good impression if it did this where it is, so I need these files to be created in the temporary…
-
4
votes1
answer9015
viewsHow to create a. BAT configuration file in windows?
I am automating some processes on a Windows server, and would like to create some files. bat for this but for such would be necessary the . BAT were able to read a configuration file so I did the…
-
4
votes2
answers1104
viewsShow an object/variable with different names in R?
Considering the following routine: x <- 1:10 for (i in 1:length(x)) { ## Nome da variável: nomevar <- paste0("Var_", i) var <- x[i] + 2 assign(nomevar, var) print(nomevar) # aqui esta minha…
-
4
votes2
answers505
viewsCalling protected variable inside static method
<?php class Foo{ protected $calc; function __construct(){ $this->calc = 2; } public static function getCalc(){ return $this->calc * 5; } } Foo::getCalc(); When I spin, he gives me that…
-
4
votes1
answer506
viewsVariable without initializing
I did a basic function of squaring (exercise of a book), and I use a variable named aux and the use to calculate the power value squared, but the compiler claims that aux is not initialized, I would…
-
4
votes1
answer415
viewsStatic public variables in C#
How can I organize my code? When programming there are variables that I am leaving in the same code at the top as: namespace myData.MySql { public partial class teste { public static string…
-
4
votes3
answers216
viewsWhy is the behavior of the undefined variable different from the undefined property?
I’ve noticed this for a long time in Javascript. If I write a certain code where the variable is not defined in any scope, an exception is thrown: console.log(preco) Upshot: Uncaught Referenceerror:…
-
4
votes1
answer1269
viewsassign variable with id dynamically via jquery
Hello What I need is this: have a form and on it I mount inputs whose values are the data of a table I run in a loop, I assign an id to each of these imputs with the field name and the number of an…
-
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
votes2
answers1128
viewsWhat does an abstract class type variable mean?
Studying Pattern design I saw something that I didn’t understand very well what it means, when we have a variable of the type of an abstract class what it means exactly? Example: ClasseAbstrata…
-
4
votes1
answer97
viewsDoes it pay to store the value of a struct member in a local variable?
I see several programmers doing this. Instead of accessing a member of a struct directly, it copies the value to a local variable to the function and uses this variable. Is there performance gain in…
-
4
votes1
answer664
viewsAccess local variable outside an if
How to create/modify a variable within a if and be able to access it without having to set it in global mode/scope. I am working on a Lua file similar to this scheme: if verificacao then local…
-
4
votes3
answers611
viewsVariable variable in php
I need to generate a variable with arbitrary name. I have the following code, which does not work: $vv = mysql_query("SELECT * FROM $tabela ORDER BY rand() LIMIT 3"); $i=1; while($v =…
-
4
votes1
answer2537
viewsWhat is the difference between pointer to vector and pointer to variable?
int A; int* pA = 1; int Vect[2] = {1,2}; int* pVect; pA = &A; *pA = 2; pVect = Vect; pVect[0] = 10; In the case I have a pointer to a variable and then to an array, and I want to change its…
-
4
votes4
answers7713
viewsHow to detect if a variable is null?
I’m trying to validate a simple form in Python 3 and I want to make sure it doesn’t record the information if the field nome is empty, but when I make a if to check whether the variable name is…
-
4
votes2
answers4695
viewsHow to change the value of a variable by function in Python?
How can I change the value of a variable through a function? Here’s an example of what I’d like to do: def func(t): t = 2 + 3 t = 7 func(t) print(t) The output of the print(t) function returns me…
-
4
votes1
answer197
views -
4
votes3
answers218
viewsPublic field X property
I have a string defined as "name" initially it is as private. string nome; In case I assign the methods get/set, and to stay in the pattern I change the initial letter to uppercase, getting: string…
-
4
votes4
answers430
viewsPrint variable inside a repeat structure
Not recognizing the variable soma because she’s inside the loop. What do I do to fix it? public static void main(String[] args) { int tipo; int restante = 0; int bim = 4; //double soma= 0; double[]…
-
4
votes2
answers477
viewsWhy is the variable not modified?
I have the following code below: #!/usr/bin/python3 # VARIÁVEIS variavel = 0 def valores(): if ( variavel == 0): variavel = 100 elif (variavel == 1): variavel = 200 elif (variavel == 2): variavel =…
-
4
votes2
answers767
viewsDifference between local variable VS global variable
In my micro controller classes the variables are always defined globally and very rarely locally and I would like to know why, because in my mind it makes a difference between being global or local.…
-
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
answers346
viewsReuse of variables
I had a question about code optimization. I assume that the more the code is dried, the faster the algorithm will be compiled and executed. Starting from this principle, I have the habit of reusing…
-
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
answers820
viewsAccept only numbers in the C#console app
Good evening, I’m trying to get the Console.Readline() command to read only numbers, ignoring characters, there’s a way ? example: static void main() { int x; Console.WriteLine("INSERINDO VALOR PARA…
-
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 ?
-
4
votes2
answers211
viewsWhy is it wrong when I try to assign a value to the variable within a conditional operator?
I have the following code that should receive 4 numbers and tell which one is the largest. #include <stdio.h> int max_of_four(int x, int z, int y, int w); int main() { int a, b, c, d;…
-
4
votes2
answers439
viewsSize of type int with short and long prefixes in C
My architecture is Unix, so by default the size of type int is 4 bytes, so far so good. In Luis Dama’s book he states that short and long prefixes solve the problem for portability of programs…
-
4
votes1
answer87
viewsWhat happens to memory space after the use of a local variable?
At the end of the execution of a function its local variables are "destroyed", correct? The spaces in memory have any values, in C we can notice when ordering to print a variable that we did not…
-
4
votes1
answer63
viewsWhat is the code convention name for variables that use _?
If variables declared as such: var camelCase = ""; follow the pattern camelCase, what is the default name for variables that use the _, as below? ruby_var = "a questão vale 10 pontos =)"…
-
4
votes1
answer63
viewsCan the use of many variables in the CSS affect page performance?
The use of many variables in CSS can end up greatly degrading the page’s performance? It is possible to say more or less the use of how many would be necessary to begin to bring a negative impact?…
-
3
votes1
answer377
viewsDefine multiple variables in one row only
I would like to parse a single line and break a string into several variables. In string which I will parse, the default is that each field is separated by a comma. In several lines, the code to do…