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 pointer in C
How do you declare a variable that will hold string values?
Write a program to swap two numbers without using the third variable?
Describe newline escape sequence with a sample program?
What are nested functions in c?
what is recursion in C
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.
what is the role you expect in software industry?
In which layer of the network datastructure format change is done
What’s the special use of UNIONS?
Explain what is a 'locale'?
How can I open a file so that other programs can update it at the same time?
What is the ANSI C Standard?
largest Of three Number using without if condition?
Mention four important string handling functions in c languages .