in Programming in C
442 views
0 votes
0 votes

int *I ,j;

I =&j; 

why it is valid since j has not been defined so no memory will be allocated to j and I is having the address of J so it must saw segmentation fault

in Programming in C
442 views

4 Comments

int j is not definition but is declaration.

no.... it is definition and declaration 

https://www.geeksforgeeks.org/variables-and-keywords-in-c/

1
1
@Shaik Masthan

oh yeah, you're right.
0
0

1 Answer

0 votes
0 votes
This is valid because in the first statement j is declared as an integer variable means the memory will be allocated to j, by default the allocated memory will contain the garbage value. In the second statement the address of j will be be saved in Pointer variable I.