Skip to content

Instantly share code, notes, and snippets.

@aji
Created May 16, 2013 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aji/5589019 to your computer and use it in GitHub Desktop.
Save aji/5589019 to your computer and use it in GitHub Desktop.
how const works
#include <stdio.h>
int main(int argc, char *argv[])
{
char a, b;
char const * s;
char * const p;
s = &a;
p = &b;
*s = '-';
*p = '-';
return 0;
}
foo.c: In function ‘main’:
foo.c:10:2: error: assignment of read-only variable ‘p’
p = &b;
^
foo.c:12:2: error: assignment of read-only location ‘*s’
*s = '-';
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment