Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Variable declarations in while loop conditions are also C++-only.
// Due to the declaration in the while-condition, this must be compiled as C++. // C99 supports declarations in the initializer of a for loop, but not in if // and while. See ISO/IEC 9899:1999 6.8.5 Iteration statements. (A freely // available DRAFT: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf.) #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { enum { maxval = 9 }; printf("Here's a handful of \"random\" numbers from 1 to %d:\n", maxval); srand((unsigned)time(NULL)); while (const int n = rand() % (maxval + 1)) printf("%d\n", n); puts("Done."); }
run
|
edit
|
history
|
help
0
MPL 2-0
K combinator - Lazy evaluation
Reverse polish notation
vector destruction - clang
hello world 3
Union-Struct-uint32_t byte order
problem_name_2
Dynamically allocated array in unique_ptr with custom deleter.
std::99 bottles of beer!
"nearest enclosing namespace"