0

What is the difference between the 2 syntax of code. Wich one is correct 1 or 2.

Typedef struct element { Int val; Struct element *suivant }element; element *init (element * L) { L=NULL; Return L; } When we will call the function init in the main 1-- Int main(){ element *a; a= init(L) 2-- Int main(){ element *a; a= init(&L);

27th Sep 2020, 3:34 PM
Amal Gil
Amal Gil - avatar
7 Antworten
0
L is undefined. What is L there? Function is getting a structure so its not primitive value so it it pass address normal way.. 1st suites but it may depend on L type also..
27th Sep 2020, 4:28 PM
Jayakrishna 🇮🇳
0
L is a pointer that point to the structure element.
27th Sep 2020, 4:47 PM
Amal Gil
Amal Gil - avatar
0
In main? Not in function. If structure pointer, 1st works.
27th Sep 2020, 4:50 PM
Jayakrishna 🇮🇳
0
No it shout be a=init(a)
27th Sep 2020, 5:42 PM
Amal Gil
Amal Gil - avatar
0
Yes. That works and thats what I saying.. a is defined so a = init(a) ; is fine. but a = init(L) error for L is undefined...
27th Sep 2020, 6:47 PM
Jayakrishna 🇮🇳
0
Is going to be a =init(a) or a =init(&a)
27th Sep 2020, 7:43 PM
Amal Gil
Amal Gil - avatar
0
amal 01 correct syntax for passing struct pointer there in your code sample is element *a; init(a);
28th Sep 2020, 1:28 PM
Jayakrishna 🇮🇳