variables

Why is it possible to declare a variable without an initial value?

谁说我不能喝 提交于 2020-01-10 03:00:55
问题 I'm reading Gilles Dowek's Principles of Programming Languanges : He says that it's also possible to declare a variable without giving it an initial value and also that we must be careful not to use a variable which has been declared without an initial value and that has not been assigned a value. This produces an error. Note: The book's author mentions the possibility of declaring variables without an initial value on Java. So, why is this declaration of variables valid? When am I going to

Java: “Local variable may not have been initialized” not intelligent enough?

我的未来我决定 提交于 2020-01-10 02:07:05
问题 Consider the following method: void a () { int x; boolean b = false; if (Math.random() < 0.5) { x = 0; b = true; } if (b) x++; } On x++ I get the "Local variable may not have been initialized" error. Clearly x will never be used uninitialized. Is there any way to suppress the warning except by initializing x? Thanks. 回答1: No, there is no way Java can examine all possible code paths for a program to determine if a variable has been initialized or not, so it takes the safe route and warns you.

Why compiler is not giving error when signed value is assigned to unsigned integer? - C++

二次信任 提交于 2020-01-10 00:52:11
问题 I know unsigned int can't hold negative values. But the following code compiles without any errors/warnings. unsigned int a = -10; When I print the variable a , I get a wrong value printed. If unsigned variables can't hold signed values, why do compilers allow them to compile without giving any error/warning? Any thoughts? Edit Compiler : VC++ compiler Solution Need to use the warning level 4. 回答1: Microsoft Visual C++: warning C4245: 'initializing' : conversion from 'int' to 'unsigned int',

How to access global variables

此生再无相见时 提交于 2020-01-09 18:58:29
问题 How do I access a variable that was declared/init in my main.go in a different .go package/file? Keeps telling me that the variable is undefined (I know that global variables are bad but this is just to be used as a timestamp) in main.go var StartTime = time.Now() func main(){...} trying to access StartTime in a different .go file but keep getting StartTime undefined 回答1: I would "inject" the starttime variable instead, otherwise you have a circular dependency between the packages. main.go

Windows Batch Variable within variable

孤者浪人 提交于 2020-01-09 11:27:05
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

Windows Batch Variable within variable

隐身守侯 提交于 2020-01-09 11:24:48
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

Windows Batch Variable within variable

和自甴很熟 提交于 2020-01-09 11:24:09
问题 In windows batch could you set a variable within a variable? Explained: So the %num% is within the variable. set num=5 set cnum=test set h1=%c%num%% Is it possible to make the percents work like parenthesis? The output should be h1=test Any help would be appreciated. 回答1: Your example in your question is a mess, but I think I understand what you are looking for: @echo off setlocal set C1=apple set C2=orange set C3=banana set num=2 :: Inefficient way without delayed expansion :: This will be

How to run a function in JavaScript every time a variable changes?

折月煮酒 提交于 2020-01-09 11:06:34
问题 Is there a way in JavaScript to have something like an event that listens to changes in a variable? so when its value is modified the event triggers and then I can call a function. To put this more into context I have a function which handles the html rendering of an array of objects, and I want that function to be called automatically every time the array is modified. Thanks. 回答1: Use object.watchdocs and if it is not supported natively look at this implementation: Object.watch() for all

Inserting Variables MySQL Using Python, Not Working

亡梦爱人 提交于 2020-01-09 10:36:11
问题 I want to insert the variable bob , and dummyVar into my table, logger . Now from what I can tell all I should need to do is, well what I have below, however this doesn't insert anything into my table at all. If I hard-code what should be written (using 'example' then it writes example to the table, so my connection and syntax for inserting is correct to this point). Any help would be more than appreciated! conn = mysql.connector.connect(user='username', password='password!', host='Host',

Inserting Variables MySQL Using Python, Not Working

泪湿孤枕 提交于 2020-01-09 10:33:06
问题 I want to insert the variable bob , and dummyVar into my table, logger . Now from what I can tell all I should need to do is, well what I have below, however this doesn't insert anything into my table at all. If I hard-code what should be written (using 'example' then it writes example to the table, so my connection and syntax for inserting is correct to this point). Any help would be more than appreciated! conn = mysql.connector.connect(user='username', password='password!', host='Host',