initialization

C# Initialize local variable once

假装没事ソ 提交于 2021-02-19 02:15:35
问题 I assume my question will be totally stupid but I have to know the answer. Is it possible to initialize a variable just once in this situation? static void Main() { while (true) { MethodA(); MethodB(); } } private static void MethodA() { string dots = string.Empty; // This should be done only once if (dots != "...") dots += "."; else dots = string.Empty; Console.WriteLine(dots + "\t" + "Method A"); System.Threading.Thread.Sleep(500); } private static void MethodB() { string dots = string

C# Initialize local variable once

送分小仙女□ 提交于 2021-02-19 02:10:09
问题 I assume my question will be totally stupid but I have to know the answer. Is it possible to initialize a variable just once in this situation? static void Main() { while (true) { MethodA(); MethodB(); } } private static void MethodA() { string dots = string.Empty; // This should be done only once if (dots != "...") dots += "."; else dots = string.Empty; Console.WriteLine(dots + "\t" + "Method A"); System.Threading.Thread.Sleep(500); } private static void MethodB() { string dots = string

Is it necessary to Initialize / Declare variable in PHP?

梦想的初衷 提交于 2021-02-17 18:44:53
问题 This question's purpose is to only gain knowledge or information for me and many like me. So my question is: Is it necessary to Initialize / Declare a variable before a loop or a function? Asking this question is for my confusion because whether I initialize / declare variable before or not my code still works. I'm sharing a demo code for what I actually mean: $cars = null; foreach ($build as $brand) { $cars .= $brand . ","; } echo $cars; OR foreach ($build as $brand) { $cars .= $brand . ",";

Is it necessary to Initialize / Declare variable in PHP?

元气小坏坏 提交于 2021-02-17 18:41:07
问题 This question's purpose is to only gain knowledge or information for me and many like me. So my question is: Is it necessary to Initialize / Declare a variable before a loop or a function? Asking this question is for my confusion because whether I initialize / declare variable before or not my code still works. I'm sharing a demo code for what I actually mean: $cars = null; foreach ($build as $brand) { $cars .= $brand . ","; } echo $cars; OR foreach ($build as $brand) { $cars .= $brand . ",";

scanf is using an uninitialized variable; C [duplicate]

霸气de小男生 提交于 2021-02-17 03:29:51
问题 This question already has answers here : why scanf scans a null value (2 answers) Closed 6 years ago . I'm sure there just a silly mistake here, however, I can't figure it out. This is part of my code: char *moving; scanf("%s", moving); When I compile it with gcc, it says the following: newmatrix.c:38:7: warning: ‘moving’ is used uninitialized in this function [-Wuninitialized] Line 38 is the scanf How do I fix this? Thanks 回答1: Allocate memory for moving before using it. Use malloc() .

Unitialized int value always the same (C++)

為{幸葍}努か 提交于 2021-02-16 20:31:27
问题 Given this code: void main() { int x; cout << x; system("pause"); } When I debug this piece of code, it always prints -858993460A. I read that its because VS set this as default value for Unitialized vars. But I also read that in release mode, this should get random value. But everytime I run this code in release mode I get 1772893972A , which Is not changing -> its not random. What is this? Why do I get this value? 回答1: The main is not the real entrypoint of the executable, in general the

Proper way to initialize a std::array from a C array

冷暖自知 提交于 2021-02-16 16:14:29
问题 I'm getting an array from a C API, and I'd like to copy this to a std::array for further use in my C++ code. So what is the proper way of doing that ? I 2 uses for this, one is: struct Foo f; //struct from C api that has a uint8_t kasme[32] (and other things) c_api_function(&f); std::array<uint8_t, 32> a; memcpy((void*)a.data(), f.kasme, a.size()); And this class MyClass { std::array<uint8_t, 32> kasme; int type; public: MyClass(int type_, uint8_t *kasme_) : type(type_) { memcpy((void*)kasme

Why does the initialisation of an object invoke the copy constructor?

梦想与她 提交于 2021-02-16 16:10:40
问题 Consider the following minimal working example: #include <atomic> int main() { ::std::atomic<bool> a = false; } Copy ctor and copy assignment of atomic are both explicitly deleted. However, this should invoke the ctor taking exactly a bool. Both g++ and clang++ complain that this line is attempting to invoke the copy ctor of atomic : $ g++ -std=c++1z a.cpp a.cpp: In function ‘int main()’: a.cpp:4:27: error: use of deleted function ‘std::atomic<bool>::atomic(const std::atomic<bool>&)’ ::std:

What Does The antialias mean in this Font render code for pygame mean?

£可爱£侵袭症+ 提交于 2021-02-16 14:21:46
问题 class Score(pygame.Surface): pygame.font.Font.render(Text, antialias, color, Background) I am trying to make a code that will implement a Text file that gets on to my pygame surface. I want It to show up on the top right hand corner of the screen. My issue is that i have no understanding what the antialias does and what do I put on the antialias code spot. Do I put an Int or some sort of String. Here is more of the code to show just to give you an idea of what i'm going for. I hope this helps

JAVA: Is it possible to use a variable outside a loop that has been initialised inside a loop?

廉价感情. 提交于 2021-02-16 13:29:07
问题 I'm a new programmer trying to practice by making a game. I want the player to be able to set their own name, as well as answer yes or no as to whether that name is correct. I did this by using a while loop. However, since the name is initialized inside the loop, I cannot use it outside. I was wondering if there was anyway to do so. My code is probably very basic and messy. I apologize for that. Scanner input = new Scanner(System.in); String name; int nameRight = 0; while (nameRight == 0) {