The following code works fine in ideone but it gives a runtime error in codeblocks IDE . Is my IDE broken or is there any programming language specific issues .
#include<stdio.h>
int main(){
int *pointer;
int num = 45;
*pointer = num;
printf("pointer points to value %d", *pointer);
return 0;
}
replace this
by
Your pointer should be pointed to a memory space before assignment of value to it.
When you define pointer in this way:
This meas that you have defined pointer but the pointer is not yet pointing to a memory space. And if you use the pointer directly without pointing it to a memory space (like you did in your code) then you will get undefined behaviour.
pointing the pointer to amemory space could be done by one of the following way:
1) pointing to a static memory
num is an int defined as a static. So the pointer could be pointed to the num memory
2) pointing to a dynamic memory
the pointer could be pointed to a dynamic memory. the dynamic memory could be allocated with
malloc()and when the memory became useless we can free memory withfree(pointer)