I have complied the following script & I am unable 2 understand the error to resolve it
Here is the following code :
char name ;
struct emp e = ("Soicher",34);
f(struct emp ee)
When writing your
main function (or any function for that matter) you have to initialize it as a type (i.e.
main I think it has to be an
int. What's happening here is, your compiler is interpreting
main as a function of type
emp, because without a type declaration before
main it assumes the
type directly precedes it, which in this case is
Essentially what you have is
struct emp main which is simultaneously creating an
emp struct and creating the
main function which returns an object of type
emp (which for any other function would be entirely valid BUT
main has to be an
main.c:4:1 warning: ...
For this SPQR is mostly right, he just forgot to add that you will also have to put a
; at the end of you emp definition of the emp type.
main.c:11:15: error: ...
This one can be confusing, but the reason why this doesn’t work it actually quite simple:
your accidentally using the really cool comma operator!
The comma operator evaluates each statement, but only returns the last operation, so what happened is that you attempted to initialize ee to 34. So all you have to do here is instead declare ee without initializing it and then initializing the individual things inside separately.
main.c:12:4: warning: ...
This here is really easy. It’s just basically the same error as before with main on line 4, you forgot to add a return type. So to fix that I would suggest
void because that means you are returning nothing which is exactly what f is doing. never never ** NEVER ** make main have a void return type, that is a terrible practice, always return an int.