Last active
May 9, 2017 00:42
-
-
Save tobin/71d93201d09974c7a72c3fbb13dcd4bd to your computer and use it in GitHub Desktop.
static const
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
const int baz = rand(); // ok! | |
baz = 99; // compile-time error. | |
static int goo = rand(); // compile-time error. | |
goo = 99; // ok. | |
// So if we want a local variable to be "really constant," we really | |
// do want to use "static const": | |
static const int foo = 22; // ok. | |
static const int bar = rand(); // compile-time error. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment