I am writing some Win32 program, and I meet a small problem, why I cannot initialize a Variable in switch case block.  just like it:  and when I do like this, it will be ok.  And now I want to know why.
3450
I've always wondered this - why can't you declare variables after a case label in a switch statement?  In C++ you can declare variables pretty much anywhere (and declaring them close to first use is obviously a good thing) but the following still won't work:  switch (val)   {   case VAL:     // This won't work   int newVal = 42;     break; case ANOTHER_VAL:     ...   break; }     The above gives me the following error (MSC):     initialization of 'newVal' is skipped by 'case' label   This seems to be a limitation in other languages too.  Why is this such a problem?
116493
In   to  he states that "In general you should not use accessor methods in dealloc (or init)." Why does mmalc say this?  The only really reasons I can think of are performance and avoiding unknown side-effects of @dynamic setters.  Discussion?
22801
In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write:  if (var1 = var2) {   ... }   instead of:  var1 = var2; if (var1) {   ... }
64835
Hopefully an easy question, but I'd quite like a technical answer to this!  What's the difference between:  i = 4   and  Set i = 4   in VBA? I know that the latter will throw an error, but I don't fully understand why.
119176
In some text it is given that we can't assign constant values to a reference variable. When I executed such a program I could do it. Is there any condition we can't assign a constant value to a reference variable?
23091
I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for the first time I assign to a variable? Or is there more to it than that?
1371
I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference?  A (quite pointless) example in Java:  a) declaration before loop:  double intermediateResult; for(int i=0; i &lt; 1000; i++){     intermediateResult = i;     System.out.println(intermediateResult); }   b) declaration (repeatedly) inside loop:  for(int i=0; i &lt; 1000; i++){     double intermediateResult = i;     System.out.println(intermediateResult); }   Which one is better, a or b?   I suspect that repeated variable declaration (example b) creates more overhead in theory, but that compilers are smart enough so that it doesn't matter. Example b has the advantage of being more compact and limiting the scope of the variable to where it is used. Still, I tend to code according example a.  Edit: I am especially interested in the Java case.
34071
Consider this:  public class TestClass {      private String a;     private String b;      public TestClass()     {     a = "initialized";     }      public void doSomething()     {     String c;          a.notify(); // This is fine     b.notify(); // This is fine - but will end in an exception     c.notify(); // "Local variable c may not have been initialised"     }  }   I don't get it. "b" is never initialized but will give the same run-time error as "c", which is a compile-time error. Why the difference between local variables and members?  Edit: making the members private was my initial intention, and the question still stands...
89893
The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?  The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set foo before importing other modules and then they would see the same value for it.
58615
Have you ever tried this before?  static void Main(string[] args) {     int x = 10;     x = x++;     Console.WriteLine(x); }   Output: 10.  but for   static void Main(string[] args) {     int x = 10;     x++;     Console.WriteLine(x); }   Output: 11.  Could anyone explain why this?
7388
Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++?  Are there any tools or thought processes that helped you understand how pointers work at the variable, function, and beyond level?  What are some good practice things that can be done to bring somebody to the level of, "Ah-hah, I got it," without getting them bogged down in the overall concept? Basically, drill like scenarios.
4974
I want to store courseworks marks of n courseworks into n variables, such as cw1 and cw2 etc. Using variable variables how can I come with cw1, cw2 etc.   How can I dynamically create variables?
13470
I am a little surprised by the following.  Example 1:  char s[100] = "abcd"; // declare and initialize - WORKS   Example 2:  char s[100]; // declare s = "hello"; // initalize - DOESN'T WORK ('lvalue required' error)   I'm wondering why the second approach doesn't work. It seems natural that it should (it works with other data types)? Could someone explain me the logic behind this?
17111
Just wondering what the difference between BeginInvoke() and Invoke() are?   Mainly what each one would be used for.  EDIT: What is the difference between creating a threading object and calling invoke on that and just calling BeginInvoke() on a delegate? or are they the same thing?
101730
What is the purpose of anonymous { } blocks in C style languages (C, C++, C#)  Example -    void function() {    {     int i = 0;     i = i + 1;   }    {     int k = 0;     k = k + 1;   }  }    Edit - Thanks for all of the excellent answers!
122980
This is my code:  internal enum WindowsMessagesFlags {     WM_EXITSIZEMOVE      = 0x00000232,     WM_DISPLAYCHANGE     = 0x0000007e,     WM_MOVING            = 0x00000216, }  protected override void WndProc(ref Message m) {     switch(m.Msg) {         case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE:             FixWindowSnapping();             break;         case (int)WindowsMessagesFlags.WM_EXITSIZEMOVE:             SaveWindowProperties();             break;         case (int)WindowsMessagesFlags.WM_MOVING:             KeepProperLocation(ref m);             break;     } }   Is there anyway to prevent the casting?
52593
Yesterday, I found myself writing code like this:  SomeStruct getSomeStruct() {     SomeStruct input;      cin &gt;&gt; input.x;     cin &gt;&gt; input.y; }   Of course forgetting to actually return the struct I just created.  Oddly enough, the values in the struct that was returned by this function got initialized to zero (when compiled using g++ that is).  Is this just a coincidence or did another SomeStruct get created and initialized somewhere implicitly?