Arjun Suresh (talk | contribs) |
Arjun Suresh (talk | contribs) |
||
Line 15: | Line 15: | ||
int *a; // This declares a as an integer pointer, meaning a can point to a memory address which contains an int | int *a; // This declares a as an integer pointer, meaning a can point to a memory address which contains an int | ||
− | + | \*a = 5; //Makes the content of the address pointed to by a 5. But a is not pointing to any valid address (int *a assigns garbage value to a) and hence this assignment can cause segmentation fault | |
<disqus/> | <disqus/> | ||
[[Category:Coding Questions]] | [[Category:Coding Questions]] |
<syntaxhighlight lang="c">
int main() {
int *a; *a=5; printf("%d",a);
return 0;
}
</syntaxhighlight>
Invalid memory access
int *a; // This declares a as an integer pointer, meaning a can point to a memory address which contains an int \*a = 5; //Makes the content of the address pointed to by a 5. But a is not pointing to any valid address (int *a assigns garbage value to a) and hence this assignment can cause segmentation fault
blog comments powered by Disqus<syntaxhighlight lang="c">
int main() {
int *a; *a=5; printf("%d",a);
return 0;
}
</syntaxhighlight>
Invalid memory access
int *a; // This declares a as an integer pointer, meaning a can point to a memory address which contains an int \*a = 5; //Makes the content of the address pointed to by a 5. But a is not pointing to any valid address (int *a assigns garbage value to a) and hence this assignment can cause segmentation fault
blog comments powered by Disqus