Arjun Suresh (talk | contribs) (Created page with "<syntaxhighlight lang="c"> #include<stdio.h> int main() { int *a; *a=5; printf("%d",a); return 0; } </syntaxhighlight>") |
Arjun Suresh (talk | contribs) |
||
| (16 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | ==={{Template:Author|Arjun Suresh|{{arjunweb}} }}=== | ||
| + | <syntaxhighlight lang="c"> | ||
| + | int *a; | ||
| + | </syntaxhighlight> | ||
| + | This declares a as an integer pointer, meaning 'a' can point to any memory address which contains an int | ||
| + | |||
| + | <syntaxhighlight lang="c"> | ||
| + | *a = 5; | ||
| + | </syntaxhighlight> | ||
| + | This 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 | ||
| + | |||
| + | {{Template:FBD}} | ||
| + | |||
| + | |||
| + | [[Category:Coding Questions]] | ||
<syntaxhighlight lang="c">
int main() {
int *a;
*a=5;
printf("%d",a);
return 0;
}
</syntaxhighlight>
<syntaxhighlight lang="c"> int *a; </syntaxhighlight> This declares a as an integer pointer, meaning 'a' can point to any memory address which contains an int
<syntaxhighlight lang="c">
</syntaxhighlight> This 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
<syntaxhighlight lang="c">
int main() {
int *a;
*a=5;
printf("%d",a);
return 0;
}
</syntaxhighlight>