Inicjalizacja wskaźnika daje błąd segmentacji
Napisałem program w C w następujący sposób:
PRZYPADEK 1int *a; /* pointer variable declaration */
int b; /* actual variable declaration */
*a=11;
a=&b;/* store address of b in pointer variable*/
Daje błąd segmentacji podczas uruchamiania programu.
Zmieniłem kod w następujący sposób:
PRZYPADEK 2int *a; /* pointer variable declaration */
int b; /* actual variable declaration */
a=&b;/* store address of b in pointer variable*/
*a=11;
Teraz działa dobrze.
Jeśli ktoś wie, proszę wyjaśnić, dlaczego w CASE 1 podaje błąd segmentacji.