How to access or modify the const variable in c ?
Answer Posted / samrat
You can modify the const variable in C by using pointers.
#include <stdio.h>
int main()
{
const int val = 20;
printf("Value is: %d\n", val);
int *ptr =(int*)&val;
*ptr = 2000;
printf("Value is: %d\n", val);
return 0;
}
Output
Value is: 20
Value is: 2000
| Is This Answer Correct ? | 13 Yes | 28 No |
Post New Answer View All Answers
What is a constant?
Explain how do you determine whether to use a stream function or a low-level function?
What is the difference between #include
What is class and object in c?
Explain what is a pragma?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
What is the difference between Printf(..) and sprint(...) ?
How can I make it pause before closing the program output window?
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
How to throw some light on the b tree?
Is register a keyword in c?
Which is the memory area not included in C program? give the reason
What is modeling?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd