Firstly here
int *unassignedPointer; /*here it can points to any unknown memory location */
unassignedPointer
is not initialized and not pointing to valid memory location & dereferencing(if you tried) it causes undefined behavior. your compiler may warn you like
‘unassignedPointer’ is used uninitialized in this function
[-Werror=uninitialized]
if you compiled your code with proper warning flag like -Wall
etc. so first initialize unassignedPointer
with NULL
like
int *unassignedPointer = NULL;
Is this a dangerous practice, or should I just ignore these warnings? one should never ignore compiler warning. Better compile any simple code with
gcc -Wall -Wstrict-prototypes -Werror test.c /* Werror, stops the compilation, convert warning into error */
Also read C
language standard, draft n1256 section 5.1.2.2.1
Program startup: It shall be defined with a return type of int and with no parameters:
int main(void) { /*
...
*/ }
or with tw op arameters (referred to here as argc and argv ,though an
yn ames may be used, as the ya re local to the function in which the
ya re declared):
int main(int argc, char *argv[]) { /*
...
*/ }
This
void main() {
/*some code */
}
is not correct, instead use
int main(void) {
/*some code */
}