About 165,000 results
Open links in new tab
  1. Where you can and cannot declare new variables in C?

    If your compiler allows it then its fine to declare anywhere you want. In fact the code is more readable (IMHO) when you declare the variable where you use instead of at the top of a function because it …

  2. How do I use extern to share variables between source files?

    The clean, reliable way to declare and define global variables is to use a header file to contain an extern declaration of the variable. The header is included by the one source file that defines the variable …

  3. Why can't variables be declared in a switch statement?

    Sep 18, 2008 · 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 …

  4. How do I declare several variables in a for (;;) loop in C?

    According to the C++ grammar (archived link), a for-init-statement (the part of the for-loop that you are asking about) can only be: a simple-declaration, e.g. int i = 5, j = 12, in which all declared variables …

  5. c - Variable declaration in a header file - Stack Overflow

    In case I have a variable that may be used in several sources - is it a good practice to declare it in a header? or is it better to declare it in a .c file and use extern in other files?

  6. Variable declaration placement in C - Stack Overflow

    I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement ru...

  7. How do I share a global variable between c files?

    Nov 26, 2015 · If I define a global variable in a .c file, how can I use the same variable in another .c file? file1.c:

  8. Why declare a variable or function static in C? - Stack Overflow

    Nov 3, 2009 · 9 The keyword static has several uses; Outside of a function it simply limits the visibility of a function or variable to the compilation unit (.c file) the function or variable occurs in. That way the …

  9. How to declare variable type, C style in Python - Stack Overflow

    Oct 14, 2010 · 12 Python isn't necessarily easier/faster than C, though it's possible that it's simpler ;) To clarify another statement you made, "you don't have to declare the data type" - it should be restated …

  10. Static variable inside of a function in C - Stack Overflow

    The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo(). The lifetime of a variable is the period over which it exists. If x were defined without the …