Skip to content

Instantly share code, notes, and snippets.

@Zulqurnain
Created September 18, 2013 15:10
Show Gist options
  • Save Zulqurnain/6610598 to your computer and use it in GitHub Desktop.
Save Zulqurnain/6610598 to your computer and use it in GitHub Desktop.
Write a C / C++ program to modify the constant variable ?
/*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