A function definition consists of a return type , a function name, a list of parameters in parentheses
I do not understand what types of function declaration is this in the following code
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>struct student
{int mark;};//What is meaning of this declaration struct* newStudent (int mark,struct student *nextstudent)void main (){//Program code //}
Can anyone help me What does this function do and What does it pass and get return ?
-first defined a structure with name as 'student' with only one member 'int mark' as:
struct student
{
int mark;
};
Then a new structure named as 'newStudent ' is defined , but
this is defined as a 'pointer to the new structure' (*newstudent)
This pointer structure contains :
-two members,
*one , with mark(int mark)
*another with an already defined structure of 'student' as a pointer in -'struct student *nextstudent'
1. void function name (void)
2. voide function name (pass parameters )
3. return result function name (void)
4. return result function name (pass parameters)
I think 4 but I do not understand what type of function is this ? What the result it return ?
By writing empty example like the definition of nextstudent, important points are left open, e.g. does it allocate storage for the returned new structure. Using the structure provided by nextstudent as in my simplistic example makes no sense for real code. But that's a context problem and not directly related to the discussed syntax question.
As a side remark, instead of repeating struct student in any variable or pointer definition, you can make a typedef and use it subsequently
Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
typedefstruct{int mark;} t_student;// optionally define a pointer type at one go // } t_student, *p_student;
t_student * newStudent (int mark, t_student *nextstudent)// alternatively, referring to the pointer type
p_student newStudent (int mark, p_student nextstudent)