Created
September 18, 2013 15:10
-
-
Save Zulqurnain/6610598 to your computer and use it in GitHub Desktop.
Write a C / C++ program to modify the constant variable ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Note : This is a Bug Code ,, in actual it is NOT POSSIBLE !! , this code will only work On MS Visual 2008 & 2010*/ | |
//Sol#1 | |
#include<stdio.h> | |
int main(){ | |
int i=10; | |
int *ptr=&i; | |
*ptr=(int *)20; | |
printf("%d",i); | |
return 0; | |
} | |
//Sol#2 | |
#include <iostream.h> | |
int main(){ | |
const int f=11; | |
int *ptr = const_cast<int*> (&f); | |
int t; | |
cout<<"Change Value Of F to :=:"; cin>>t; | |
*ptr = t | |
cout<<f; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment