Parameter transfer:
PASS Parameters by value
ADT & black box
ADT: abstract data type, abstract data type
C can be used to design and implement abstract data types because it can restrict the scope of functions and data definitions. This technique is also called Black Box Design.
User. h
# Define MAXLEN 3 struct UserClz {char * name; char * phone; char * address;}; typedef struct UserClz User; /** */char const * lookupAddress (char const * name ); /** call the function * To find the phone number by location */char const * lookupPhone (char const * name );
User. c
# Include "user. h" # include
# Include
/** Restricted access scope */static User users [MAXLEN] = {"user1", "111", "aaa" },{ "user2", "222 ", "bbb" },{ "user3", "333", "ccc" }}; void init () {int j = 0; for (j = 0; j
Name, name) = 0) {return pu + I;} return NULL;} char const * lookupPhone (char const * name) {User const * pu; pu = getUserByName (name); if (pu! = NULL) {return pu-> phone;} else {return NULL;} char const * lookupAddress (char const * name) {User const * pu; pu = getUserByName (name); if (pu! = NULL) {return pu-> address;} else {return NULL ;}}
Main. c
#include
#include "user.c"void main(){init();printf("phone=%s\n",lookupPhone("user1"));printf("address=%s\n",lookupAddress("user2"));}
The above is a black box example. The function of the ink cartridge accesses the module through the specified interface, and the interface functions include lookupPhone and lookupAddress,
Users cannot directly access data related to the module implementation, such as users and getUserByName, which are declared as static
Recursion
Calculate the number of fipona
#include
int fn(int n){if(n<=2) return 1;return fn(n-1)+fn(n-2);}void main(){printf("result:%d\n",fn(5));// result:5}
Process Diagram