Most voted "variable-declaration" questions
The declaration of a variable occurs when a variable is created.
Learn more…129 questions
Sort by count of
-
3
votes1
answer61
viewsIs it possible to initialize a structure partially indicating the members?
In several languages it is possible to initialize a struct, or class, indicating which members want to put some value: var obj = new Tipo { b = 1, e = "x" }; In C we can initialize members in order:…
-
3
votes2
answers224
viewsWhy do you use extern?
According to what I researched, the reserved word extern in C is used to inform that the declared variable is somewhere else in the program. A variable extern is useful for saving memory, because…
-
3
votes2
answers64
viewsIs declaring variable receiving element of a vector within a for a good practice or is it unnecessary?
//code 1 var pacientes = document.querySelectorAll(".paciente"); for(var i = 0; i < pacientes.length; i++){ var paciente = pacientes[i]; //linha desnecessária…
-
3
votes2
answers92
viewsHow to make a function that takes two integer vectors and returns a boolean value?
I want to make a function that takes two integer vectors and returns a value Boolean, but when I put the: return (encontrou); It keeps error on the variable encontrou. Follows part of my function:…
-
3
votes2
answers69
viewsFor loop build error
I’m making a program that asks how many notes the user will type and after that, enters a 'for' loop asking what are the notes to type. Notes are stored in a array and finally the average. #include…
-
3
votes1
answer38
viewsI don’t understand this form of static variable declaration
Why this statement seems neither method nor attribute? static{ } this is the original code private static MessageDigest md5 = null; static { try { md5 = MessageDigest.getInstance("MD5"); } catch…
-
3
votes1
answer474
viewsIn C, can declaring variables in the middle of a block of code lead the program to undefined behavior?
I have read in several books that in C variables should be declared at the beginning of a code block. But what happens if I declare them in the middle? I was doing a program in c that shows a text…
-
3
votes2
answers499
viewsDefine a generic variable without defining the type
I’m doing some tests on Unity so I can practice programming. I’m new and this question can be kind of stupid. I want to know if this is possible: I created the following abstract class: public…
-
3
votes2
answers88
viewsCan you create variables within a block and use them later?
do local a2 = 2*a local d = sqrt(b^2 - 4*a*c) x1 = (-b + d)/a2 x2 = (-b - d)/a2 end -- scope of `a2' and `d' ends here print(x1, x2) …
-
3
votes1
answer135
viewsUse of typedef for pointer
If I’ve already set a pointer to my structure why can’t I make the allocation of it. #include <stdio.h> #include <stdlib.h> struct ponto { int a, b; }; typedef struct ponto *Ponteiro; //…
-
3
votes1
answer95
viewsProblem in javascript variable declaration
Can anyone explain to me what the problem is with the word 'name' in Javascript? see this code: the result of the first code will say that the variable name is an object and that name is a string,…
-
3
votes2
answers1022
viewsError: incompatible type for argument 1 of 'printf'
I have this activity, exercise, where is to display the largest number, but is giving the error: "incompatible type for argument 1 of 'printf' " On the command line "printf (valor2);". Code:…
-
3
votes2
answers165
viewsVariable appears as undeclared when trying to use it in the "while" loop
When trying to create a program that converts Celsius into Fahrenheit to get practical and I come across the following error message: Erro "sair " undeclared (first use in this function) My…
-
3
votes1
answer62
viewsDifference of {} and = in a declaration
What is the difference of two statements? On what occasions should I use each one? - int Num{15}; - int Num = 15;
-
2
votes2
answers155
viewsHow to turn strotime output into a variable
I’m trying to use this script, which returns every Monday between two periods: $beginday = isset($_POST["Tinsem3"]) ? $_POST["Tinsem3"] : false; $lastday = isset($_POST["Tdesl"]) ? $_POST["Tdesl"] :…
-
2
votes4
answers222
viewsDoubt in jQuery variable creation
Researching materials on jQuery I noticed that some articles use two types of variable declaration, some using the dollar sign and others not, as in the example below: Alternative 1 var $row…
-
2
votes1
answer74
viewsWhy "new Array" after variable?
Why put new Array after the variable name? Example: var weatherPattern = new Array('Clouds', "raining", "clowdy");
-
2
votes2
answers355
viewsAdvantage in giving null in a variable on Android
Assign the value of null in a variable on Android can improve application performance? As far as I know, in Java we have the Garbage Collector, and in Android, the activity cycle of Activities and…
java android null variable-declaration garbage-collectorasked 7 years, 3 months ago Guilherme Ramos 343 -
2
votes1
answer1438
viewsVariable Declaration with Default Value in Procedures
You could declare a variable with a default value in Procedures? procedure TfrmManutencao01.FormShow(Sender: TObject); var lPriAber : Boolean = True; begin . . . end; I know that as it is above…
-
2
votes1
answer249
viewsHow to count the number of all instances of a class and their respective subclasses?
I have a class A, where A extends into B and in C. I have a counter of instances in A. public Class A { ... private int nInstancias = 0; ... public A(){ nInstancias+=1; ... } ... public int…
-
2
votes1
answer208
viewsHow to declare a multidimensional array using new
How do I declare a multidimensional array using new ? A normal array would look like this: int* ponteiro = new int[5]; But int* ponteiro = new int[5][5]; does not compile ! but int array[5][5];…
-
2
votes1
answer153
viewsDelphi 10.1, Function that only accepts an integer interval in the variable
It sounds easy, but I’m not getting it. I want to be able to define a type of variable when creating a Function or Procedure, but only accepting integers between 1 and 4 for example during the…
-
2
votes2
answers130
viewsLocal variable declaration in a PYTHON function
def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() result-> 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 But if I declare the variables a and b in different…
python python-3.x function variables variable-declarationasked 6 years, 3 months ago Rafael Eduh 51 -
2
votes1
answer105
viewsError creating variable inside IF
I was creating a script that always worked with me, however, I made a small change that almost blew my mind because I didn’t understand what happened and I didn’t find anything on the subject. Is…
-
2
votes1
answer993
viewsCopy the value of a list variable to a python variable
I’m declaring a variable X with the value of another Y using =, but when having do a append in the variable X, to Y also changes. Code: ''' Resultado obtido: ['casaRJ', 'casaSP', 'casaDF', 'apRJ',…
-
2
votes2
answers172
viewsInitialize variable in a "for"
I remember that in C language I didn’t need to initialize the variable (in case i) with a value, I tried to do the same on C# and got a build error. In C# I am required to set the value of the…
-
2
votes0
answers208
viewsA var, or Let or const has performance difference for several?
I have seen numerous answers that say it’s just a matter of style, which is good practice due to Hoisting, but I wanted to know numbers (I don’t know how to get them) on the performance aspect.…
javascript variables performance variable-declarationasked 4 years, 8 months ago Paulo Rogério da Silva 54 -
1
votes2
answers202
viewsChange class vector size
I have to use vector public static String vetor[] = new String [15]; in the class... but this class is used in a Servlet. And the size I need the vector is what the user chooses... how can I pass…
-
1
votes1
answer168
viewsHow to simplify the use of str_replace
As I explained in this question, I’m using the maskMoney to generate a coin mask in multiple fields input of type="text", only when I perform arithmetic operations with the values obtained, and then…
-
1
votes1
answer311
viewsVariable not defined in Python for-loop
I have a problem in a code that should read 4 values using raw.input().split() and then a for-loop to turn such values into float. The interpreter returns to me: "name 'val' is not defined" Follows…
-
1
votes2
answers959
viewsInstantiate an object through the interface and access methods not present in it
I have the following interface: interface something { void doSomething(); } And I have a class that implements this interface and adds another method that does not contain in the interface: public…
-
1
votes1
answer98
viewsFunction is zeroing last vector value
#include <stdio.h> #include <stdlib.h> /** 2. Faça um programa que, a partir de um vetor de 12 posições, crie funções para: A. Digitar valores no vetor; B. Imprimir o valor somatório de…
-
1
votes1
answer248
viewsWhat is the reason why a vector with no set size does not work?
If you create a vector: Thus int Vetor[0]; works #include <iostream> using namespace std; int main() { int vetor [1]; vetor[0] = 12; cout << vetor[0] << endl; } Thus int Vetor[];…
-
1
votes3
answers62
viewsMemory and processing - Variables and verification
Is there a big difference for memory and processing in how to perform the verification in these two examples? If yes, why and how they both behave when executing the codes. Method 1: var exam =…
-
1
votes2
answers1267
viewsHow to create a vector by joining together 2
I’m doing an exercise with vectors where I need to read two vectors of 5 positions each, and after that, concatenate these two into a 3 of 10 positions. My program is correctly printing the first…
-
1
votes2
answers333
viewsSingle variable declaration for scanf
I already know how to declare a variable in the traditional way using the scanf(), but I’m thinking of a way that I can use fewer lines and make the code more organized (that’s what I tried with the…
-
1
votes1
answer6433
viewsPython local and global variables
I have a software that treats dates, written as follows: def EscolheDataInicio(): controle1 = None controle2 = None if controle1 == None: teste = easygui.ccbox(msg="Escolher data início?",…
python variables variable-declaration global-variablesasked 7 years, 1 month ago Bergo de Almeida 181 -
1
votes1
answer299
viewsWhat is the default value of a primitive type variable in C#?
When a primitive type variable is created but not initialized its value is null? Example: public int x; If I don’t do anything with x, which means I don’t assign a value to it, it will be null?…
-
1
votes2
answers138
viewsAre variables declared within blocks or subprograms dynamically allocated?
I’m reading the book "Algorithms and Programming with Examples in Pascal and C" and in it there are two paragraphs that left me in doubt, are they: Two alternative forms are offered by some…
-
1
votes1
answer272
viewsHow to start an array with the value the user type is possible?
If all allocated memory is defined at the time of compilation, then how is this possible: int num{0}; cin >> num; int array[num]; From what I understand, this could only be possible if using…
array c++ memory-management allocation variable-declarationasked 6 years, 5 months ago silash35 483 -
1
votes2
answers327
viewsHow many times will the x variable be created at the end of the loop? Why?
In the following loop, how many times the variable x will be created at the end of loop? Why? for (int i = 0; < 10; i++) { double x = i + 10; System.out.println(x); }…
-
1
votes1
answer165
viewsI can’t fill a matrix
When I put fixed values in the size of the matrix I can fill it, but when I try to capture the values in matrices a message like this appears: The index was outside the matrix boundaries ` int a =…
-
1
votes1
answer125
viewsWhat is the difference between char (*ptr)[20] and char *ptr[20]?
I’m studying pointers and came across these statements, but I couldn’t understand it very well. Could you help me? Thank you.
-
1
votes2
answers69
viewsWhat is the difference between these two statements?
Let’s say I created a struct point that gives a certain point in a "map". struct Ponto { let x: Int let y: Int init(x: Int, y: Int) { self.x = x self.y = y } What would be the difference between…
-
1
votes1
answer29
viewsDoubt about variable declaration
Hello! Before opening this question, I researched to see if there was any similar open, but I could not resolve my doubt. If there is one and you can provide me the link, thank you. I don’t know…
-
1
votes2
answers741
viewsHow do I put the value of a variable in a statement of another variable?
NomeDoProduto1 = str(input("Qual o seu primeiro produto? ")) NomeDoProduto2 = str(input("Qual o seu segundo produto? ")) NomeDoProduto3 = str(input("Qual o seu terceiro produto? ")) PrecoProduto1 =…
-
1
votes2
answers233
viewsVariable is not being found
Why the following program does not work? package javaapplication1; import java.util.Scanner; public class Exemplo008 { public static void main(String[] args){ Scanner teclado = new…
-
1
votes2
answers214
viewsWhy does the value always return 0?
In the code below the result of the variable valor_1 always is 0. But reversing the order of the variables declaration to unsigned char valor_2, valor_1; the program works correctly. What’s the…
-
1
votes2
answers342
viewsUse of the unassigned local variable of two strings in C#code
My code should be entered the gender of a person, height and age of a person in a repeat loop for 10 people. The code must show the greater weight, lower weight, average height of 10 people, the…
-
1
votes0
answers262
viewsDeclare and reference a variable in Firebird SQL Editor Context
it is possible to declare and reference a variable in the context of SQL Editor? I know how to do it in Mysql. For example, follow a Mysql example of what I want. SET @var = 10; SELECT @var; Thanks…