How to access or modify the const variable in c ?

Answers were Sorted based on User's Feedback



How to access or modify the const variable in c ?..

Answer / skp

@Answer #7 - Answer of #6 is correct.

In Dev C++ the output is as answer #6.

Is This Answer Correct ?    0 Yes 2 No

How to access or modify the const variable in c ?..

Answer / ramya

const int x = 10;
int *ptr = &x;
*ptr = 20;
printf ("Value of x is %d\n", x);

Even though the variable x is const the value gets changed..
And its one of the drawback in c..

Is This Answer Correct ?    28 Yes 31 No

How to access or modify the const variable in c ?..

Answer / raj

@Ans No #9

Actually we are here discuss about how to modify value
store in the constant variable.
I don't more ,but i think in the last we have value of 'z'
same as before corrupted.

please reply me if any one have the answer of this question.

Is it possible or not??

Thanks

Is This Answer Correct ?    2 Yes 8 No

How to access or modify the const variable in c ?..

Answer / santhi

we can access the constant variable in c through the
functions which are declared as constant.

Is This Answer Correct ?    13 Yes 22 No

How to access or modify the const variable in c ?..

Answer / 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

How to access or modify the const variable in c ?..

Answer / vignesh

@Ramya
const value cannot be changed...you declared it wrong,

int *ptr = &x;

is not correct.It should be,

int ptr = &x;

also,according to your program only the *ptr value is 20 and
not the value of x

Is This Answer Correct ?    5 Yes 51 No

Post New Answer

More C Interview Questions

which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

0 Answers  


biggest of two no's with out using if condition statement

5 Answers  


for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable

2 Answers  


In CMM or CMMI certified organizations,we assess only the standard software processes of the organization. We do not assess the organizations other functional departments like HR or Admin. Then how can we certify the entire organization as CMM level company?? We have assessed only software related activities. Right. There is no relation with other departments like Accounts, HR or Admin. Then how can we claim that the whole company is a CMM certified company?

1 Answers   Melstar,


Write a c program to enter a string of paragraph and replacing a particular word which is repeated in the paragraph by another word?

2 Answers   ME, Synfusion, Wipro,






When can you use a pointer with a function?

0 Answers  


What is a structure in c language. how to initialise a structure in c?

0 Answers  


What are type modifiers in c?

0 Answers  


What does sizeof function do?

0 Answers  


What is difference between far and near pointers?

0 Answers  


my name is nani i completed my b-tech in hyd now i want go for interveiw but i dont know the process of software field interveiws plz help me anyone how many rouds there n what rounds plz plz plz help me n where i can get these details

2 Answers  


How can I use a preprocessorif expression to ?

0 Answers  


Categories