685 questions
2
votes
1
answer
176
views
What is the difference between alias `our` and the original global variable?
This is one question encountered while reading the answer of this QA (as ikegami's comment says, how subroutine foo works is complicated. IMHO that may be due to using one outside variable):
sub foo { ...
1
vote
1
answer
177
views
Does "Declaration Reflects Use" Rule Apply to C++ Reference Variables?
I'm reading some sections of "The C Programming Language" by Kernighan and Ritchie. In the pointers section, the authors state:
"The syntax of the declaration for a variable mimics the ...
0
votes
2
answers
87
views
Declaration Statement Format Difference
I'm a beginner learning C programming and I'm wondering the difference between these two formats and why one works and the other does not:
// this one doesn't work
#include <stdio.h>
int main(...
0
votes
2
answers
79
views
Incomplete type cannot be defined
I am attempting to set up some header files for a game, however, attempting to set up variables in my main file's header file causes an incomplete type error.
Both types have full definitions in their ...
1
vote
3
answers
95
views
How can I use a declaration pattern outside of an if condition?
I'm trying to use declaration patterns as described here: https://learn.microsoft.com/dotnet/csharp/language-reference/operators/patterns#declaration-and-type-patterns
I can see that the examples only ...
-1
votes
1
answer
50
views
Variable used inside function reported not used
This works fine:
package main
var foo string
func main() {
fn := func() {
foo = "AAA"
}
fn()
}
But if we move the variable declaration inside main():
package main
...
-4
votes
1
answer
69
views
Why doesn't this C++ code cause a conflicting declaration error? [duplicate]
Why doesn't the two different declarations of the variable 't' within the same function cause a conflicting declaration error? (Because it doesn't). Can this way of using the same name for a variable ...
-2
votes
4
answers
381
views
Why would anyone declare a variable before defining it? Please provide example [closed]
I'm just now learning c# (my second language, first being python) and i thought it was strange that you could declare variables before ever defining what they are. Here's what I mean:
string str;
//...
2
votes
0
answers
124
views
Writing a compiler frontend. When should I check if a variable was declared or not?
I'm currently writing a compiler in C for my own programming language.
Now I'm working on the front-end. I've added functions recently, and now I have troubles with checking if a variable was declared ...
3
votes
2
answers
485
views
how to declare an array with explicit type in vlang?
I am trying to declare an array like below
arr := [
[0, 0],
[1, 2],
[2, 4],
]
// type: [][]int
but the type I am getting from the inference is [][]int, instead I want to declare [][]float32. ...
2
votes
1
answer
145
views
Inline variables aren't working in TMS Web Core
When I try to use an inline variable, then I get a Syntax error. Here's my code:
procedure TfrmMain.btnSignInClick(Sender: TObject);
begin
var UserEmail := edtEmail.Text;
var UserPassword := ...
0
votes
1
answer
76
views
C - Struct variable inside callee function, should it be a pointer or dosent it matter
im kinda confused how memory allocation for struct variables works and how the struct variables declaration works.
My understanding is, that when im declaring a struct variable outside of a function, (...
2
votes
2
answers
137
views
Can I declare an array of integers in JSON without listing each element explicitly?
I want a JSON array to contain all integers between 0 and 1000, but I don’t want to declare each element of that very long array individually. Is there a more economical/elegant way to declare that ...
0
votes
1
answer
79
views
my variable resetting after one loop in a for loop, not sure why
i have been trying to make a for loop where at i < j. Variable J takes the length of a string to decide how many loops will happen. This works for the first loop, i have debugged and J does get the ...
1
vote
0
answers
35
views
Can't pass lat, lng to weatherbit API, ReferenceError: data is not defined
I'm really struggling with my final project for my first ever coding course. Situation:
I'm able to successfully retrieve data from Geonames API, that looks like this:
Geonames API response: {
lat: ...
1
vote
2
answers
601
views
Why Does PowerShell Complain It Can't Retrieve a Variable?
I'm getting the following error message:
The variable '$dateTime' cannot be retrieved because it has not been set.
The error is generated by the line [DateTime]$dateTime in this code:
[string]$...
0
votes
1
answer
195
views
Is it possible to declare a type with a set bit width in c++ without using a struct?
It's been at least a decade since I last touched C++. Supposedly, C++ has had a minor overhaul. Is there a way to specify the bit width of a type without using struct, class, or union bitfields? The ...
1
vote
0
answers
59
views
Error in setting up my Fyne container, not initialized or declared properly
I am trying to initialize a container for my Fyne GUI,
I declared it globally here:
var w fyne.Window
var content *fyne.Container
Then I initialized it in main()
func main() {
a := app.New()
w = a....
0
votes
1
answer
51
views
Why isn't variable 'result' always declared?
I am working with pseudocode taken from Exploration Tools (section "Arm A64 Instruction Set Architecture", button "Download XML").
bits(16) BFSub(bits(16) op1, bits(16) op2, ...
0
votes
1
answer
81
views
String concatenation with string literal and non string literal [duplicate]
I want to understand what the following declaration means:
constexpr auto type = u"bluetooth-opp-transfer-complete"_ns;
I know constexpr evaluates things at compile time, but what does u ...
0
votes
1
answer
588
views
Declaring and Writing a For Loop in Pseudocode
I am working on writing the pseudocode for a calorie counting program that calculates the total weekly calories for breakfast. the program should allow the user to enter the number of calories ...
0
votes
3
answers
2k
views
in C, why do variables need to be declared before use but functions dont?
I'm reading K&R and started wondering, why do variables need to be declared before they are used,
but functions dont?
In C, all variables must be declared before they are used, usually at the ...
8
votes
6
answers
3k
views
Destructuring an array using spread operator on left side of assignment to collect all remaining elements in a single variable
I want to perform Destructuring in php just like in javascript code below:
[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(a,b,rest);
Output:
10 20 [ 30, 40, 50 ]
How can I preform that ...
6
votes
3
answers
924
views
What is the difference between a declarator and a direct-declarator?
In The C Programming Language, 2nd Edition, by authors Brian W. Kernighan and Dennis M. Ritchie, they talk about declarators and direct-declarators. The discussion starts in the book on p. 122 with ...
0
votes
1
answer
40
views
Why does initialising the variable outside the event handler and then reassigning it only allow the code to work once?
I'm making a BMI calculator and it works only one time. Which I don't understand. I initialised 2 let variables outside the click event handler just to get the input elements. When I wanted to convert ...
0
votes
1
answer
553
views
How do I prevent re-declaring a variable in a react component when it renders?
I have a React component called Flightlist, which receives an object from its parent component via props.newFlight.
I would like to push each object received from the parent to a local array, called ...
0
votes
2
answers
98
views
Why aren't my for loops working in this bubble sort function in C
I was having this problem to which I have come to the solution through the trial and error process but I have no idea why my bubble sort function wasn't working in the first place.
The problem had to ...
-2
votes
1
answer
45
views
Must declare the scalar variable when updating my database
my code:
SqlConnection con = new SqlConnection(@"DATA;");
SqlDataAdapter cmd = new SqlDataAdapter();
cmd.InsertCommand = new SqlCommand(" UPDATE TIME ...
0
votes
3
answers
185
views
Variable declaration style in C# [closed]
Which one is recommended while writing Clean Code in C# or it doesn't matter?
a)
int count = 0, sum = 0;
b)
int count = 0;
int sum = 0;
I personally write code with b) style. I almost forgot that we ...
-4
votes
1
answer
94
views
declaring a variable in C++
I found this in a program. What does it mean?
uint8_t x(uint8_t, uint8_t, uint8_t)
I'm new to C/C++ and I'm poking around the net to see how others are doing things. I'm sure there's a way to google ...
0
votes
0
answers
38
views
C# Trying to save a picture from a user in a web browser
I am trying to allow a user to insert a file and then send it in an email, but I don't know how to receive that file. There is an error on the "System.IO.File" part of my code that says &...
0
votes
1
answer
144
views
Use declared variable in instance definition in Haskell
I'm trying to implement (a simplified version of) Representable for my data type, but I'm not allowed to use the first data type parameter in the definition:
question.hs
-----------
{-# LANGUAGE ...
0
votes
3
answers
967
views
Declare a let variable without assigning a value in Javascript, why that is?
I found this in Javascript.info : enter link description here.
Well it's a event delegation demonstration : a 9-cells table, when we click one of cells, the cell (event.target) changes its color into ...
2
votes
2
answers
1k
views
C++: Best way to declare a variable to hold the return value of a function?
I believe the following is a relatively common pattern (the exact types used are not important, they're just for example):
std::vector<std::string> manufactureVector(int param1, const std::...
-1
votes
1
answer
88
views
C#: how to declare variable inside a Loop using a index. Pseudo Code ` For (int i...) {MapPolyline map+i = new MapPolyline(); .....}
I have seen at stackexchange some answers with C++ but I need the answer at C#, please.
I must use a loop to add several MapPolylines to a map. If I don't declare a new one the last MapPolyLine is ...
0
votes
1
answer
392
views
How do I concatenate a string to a variable declaration in Ruby?
I wonder if it is possible to concatenate a variable value or a string to a new variable value declaration in Ruby.
foo = "something"
#new variable declaration:
var_ + foo = "concat ...
0
votes
3
answers
51
views
what's wrong with my program,so only the letter i can't be counted?
So here, I want to solve one of the problems in my basic programming class. So, the problem is, we should count the vowel letter and print how many A/a, I/i, U/u, E/e, and O,o letters are in a string. ...
1
vote
0
answers
52
views
C# Storing Declaration and Type Pattern Result Causes CS0165 (Use of Unassigned Local Variable)
I'm curious why both of the following code segments produces error CS0165: Use of unassigned local variable 'i':
// Attempt #1
object obj = 4;
bool isInt = obj is int i;
if (isInt)
Console....
0
votes
1
answer
48
views
Different behaviors between the same var name and function name VS two same function name [duplicate]
Recently, I received this interview question, I know it's weird to declare var name and function name the same, but the code runs without errors, and I don't know how to explain this behavior, hence ...
0
votes
0
answers
13
views
Typescript / Babel / ESLint plugin to properly use variable declared in case blocks [duplicate]
It turns out you can declare a variable in one case block and use it in another! At least in compile time anyway, at runtime it will throw an error or be undefined, depending on the interpreter ...
1
vote
0
answers
81
views
JavaScript - Variable re-declaration within a while
Why are const declarations within a while loop not an issue? Isn't the same variable being redeclared in each iteration?
In the code below, the arrValue variable is declared within the loop. I felt ...
1
vote
5
answers
7k
views
How to initialize a multidimensional array
My problem is I want to initialize a multidimensional array declared like this:
int[][][] my3DArray;
However, the following code gives me an error on [sizeY][sizeZ] saying it expected ',' or ']'.
...
-1
votes
2
answers
785
views
Wrap all variable declarations in a function
I have a Javascript function declartions as a string (gotten from Function.toString), and I want to wrap all variable declarations with a function (also in Javascript), E.g.
const value = 42 to const ...
0
votes
1
answer
2k
views
Expecting member declaration even though the val is declared the line above
I looked at all of the other questions about this error, but none of them helped. I am trying to create a reference to a button in my layout file, and when I set the onClickListener, I get "...
0
votes
1
answer
2k
views
Can not safely replay call when trying to assign and use a variable in procedure
I am trying use the data from a column in one table as column aliases of another table.
DECLARE
var1 VARCHAR(20),
var2 VARCHAR(20);
BEGIN
WITH
TABLE1 AS (SELECT ROWNUM RN, * FROM TABLE)
,A1 ...
0
votes
2
answers
52
views
Invalid type argument of ->. Help me understanjd pointers?
So I am learning pointers and i think I mostly understand how they work but Im still learning how to use them correctly.
I wrote this code that receives a pointer to a list with pointers innit, each ...
1
vote
2
answers
55
views
I don't need an output of a function, how to give it undeclared address to store that output
I just started learning C.
I have a function with two outputs, a value and an estimated error.
double result, abserr;
gsl_deriv_central (&f_var, rho, 1e-8, &result,&abserr);
I only care ...
0
votes
0
answers
58
views
Can I use Date components in a variable name in swift and, if so, how?
I am using a struct to store records that include many optional fields, e.g.,
struct record {
var age: Int?
var ID: String?
var firstName: String?
var lastName: String?
}
Ideally I ...
0
votes
1
answer
500
views
How to make regex pattern static?
When I try to make static pattern variable I receive an error: Modifier 'static' not allowed here. I can't see any reasons, why it doesn't work. Do you have any ideas?
This is how I try to do it:
...
0
votes
1
answer
1k
views
Declare a value in Sparksql in Databricks
I wanted to declare a fixed value before implementing various chunks of queries, and tried the following method. Unfortunately, no values are returned. Any advice will be much appreciated.
SET ...