【23xiu.com-爱上秀-教育信息门户网】
a test for the c programming language
i. history
1. c was originally designed for and implemented on the (what) operating system on the dec pdp-11, by (who) .
2. the most recently approved ansi/iso c standard was issued in (when) , and single line comments notation “//” is or isn’t a feature of c89.
ii. syntax and semantics
1. in a runtime c program, auto variables are stored in , static variables are stored in , and function parameters are stored in .
a. stack b. heap c. neither stack nor heap
2. the statement “extern int x;” is a , and the keyword extern is used during .
a. variable declaration b. variable definition
c. compilation time d. runtime
3. there is a complicated declaration: void ( * signal (int, void (*)(int)) ) (int);
if a statement “typedef void (*p) (int);” is given, please rewrite this complicated declaration.
4. the following code is a segment of c program.
..........
void func(int *p)
{...........}
..........
main()
{
int num=0;
.........
func(&num);
........
}
..........
here, the function argument “&num” is passed .
a. by value b. by reference
iii. practice
create a tree, which has h (h>0) layers, and its each node has w (w>0) sub-nodes.
please complete the following incomplete solution.
#include
#include
struct tree{
char info;
p_sub; //link to sub-nodes
};
// allocate memory and initiate
void dnode ( struct tree* tmp )
{
=malloc( sizeof (struct tree) );
= 0x41;
= null;
}
struct tree *dtree (struct tree* subtree, int height, int width)
{
int i;
if ( !subtree ) //if necessary, allocte memory for subtree
denode(subtree);
if ( height == 1 )
return subtree;
else if ( height == 2 ) {
struct tree *leaf = null;
for ( i=0; i
denode ( );
;
leaf = null;
}
return subtree;
}
else {
for ( i=0; i
}
return subtree;
}
}
main()
{
.........
struct tree *root = null;
root = dtree (root, h, w) ; // h and w are integers get from input
.........
}