-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst_declaration.c
47 lines (36 loc) · 1.28 KB
/
const_declaration.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/////////////////////////////////////////////////////////////////////
// April 1, 2017
//
// const_declaration.c
//
// OUTPUT:
// memory address of globalConstInt = 0x400628
// memory address of localConstInt = 0x7ffe3cfd300c
// memory address of constInt = 0x4006a8
//
// EXPLANATION:
// Explains how the location of 'const' declaration matters.
//
//////////////////////////////////////////////////////////////////////
#include <stdio.h>
const int globalConstInt = 100;
void
modifyVariable()
{
const int localConstInt = 50; // <=== Although this has 'const' qualifier,
// the variable is still is stored in stack memory space
// which is not read only. Once this procedure
// is done executing, this variable is lost.
static const int constInt = 100; // This variable will not get lost.
printf("memory address of localConstInt = %p\n", &localConstInt );
printf("memory address of constInt = %p\n", &constInt );
//localConstInt = 200;
}
int
main(void)
{
printf("memory address of globalConstInt = %p\n", &globalConstInt );
//globalConstInt = 200;
modifyVariable();
return 0;
}