Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Differentiate fundamental data types and derived data types in C.

0 Answers   HCL,


hi, which software companys will take,if d candidate's % is jst 55%?

0 Answers  


User define function contain thier own address or not.

2 Answers  


Explain the difference between null pointer and void pointer.

0 Answers   TCS,


Are global variables static in c?

0 Answers  


what is the advantage of function pointer

16 Answers   CMC, CS, Freshdesk, L&T, LG Soft, Matrix, TCS,


What is an endless loop?

0 Answers  


Why can’t we compare structures?

0 Answers  


Is c# a good language?

0 Answers  


which is conditional construct a) if statement b) switch statement c) while/for d) goto

0 Answers  


Can 'this' pointer by used in the constructor?

0 Answers  


What is the use of #include in c?

0 Answers  


Categories