Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

constant qualifier

$
0
0

this function is giving value 10 after modification in main but when printed in fun(), it is giving modified value.. how is this happening??

#include<stdio.h>

#include<conio.h>

void fun(const int *s)
{
printf("In this function %d\n",*s);
}

int main()

{

const int a = 10;

int *p = (int*)&a;

printf("before modification a=%d\n",a);

*(int*)&a = 12;

printf("after modification a=%d\n",a);
fun(&a);
getch();

return 0;

}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>