-------------------
int a=1;
int b=2;
int c=3;
int *p;
int *q;
c=*p;
p=q;
--------------------
Q3:what are the values of *p and *q and c?
A3:
*p =2; *q =2; c =1;
--------------------
Question setup:
--------------------
int *p;
int *q;
*p=12;
q=p;
--------------------
Q4:what is value of q?
A4:
程序会报错
--------------------
----------------解决方案--------------------------------------------------------
Question Setup:
--------------------
void foo()
{
int a=1;
int b=2;
bar(a);
bar(b);
}
void bar(int p)
{
int q;
q=p+2;
}
--------------------
Q5:what are values of integers a and b end of foo()?
A5:
a 还是1 ;b 还是2
--------------------
Q6:Modify the above functions,using pointers,so values at the end of
foo() are a=3 and b=4
A6:
这个是正确的
-----------------------
----------------解决方案--------------------------------------------------------
LINKED LIST BASICS
Q7:what is an example of a structure and pointer to that structure?
A7:
struct Student
{
int ID;
char* Name;
bool Sex;
int Age;
};
Student *pStu;
------------------------
Q8:use the struct pointer created above to assign a member of the structure
the value 5?
A8:
pStu->Age =5;
---------------------
Q9:allocate a structure to be used in a single data integer linked list
A9:
list<int> Next_node;
--------------------
Q10:Use the linked list data structure above to create a function that
builds a list of {1,2,3} and returns pointer to beginning of list.
A10:
Next_node->push_frond(1);
Next_node->push_frond(2);
Next_node->push_frond(3);
Next_node->frond();
--------------------
Q11:Write a function to count number of elements in the list
A11:
list<int>::iterator item;
int Count =0;
for(item=Next_node.begin();item!=Next_node.end();item++)
Count++;
--------------------
----------------解决方案--------------------------------------------------------
ADVANCED LINKED LIST EXAMPLE
Q12:Use the code snippet below.what do you call this type of function?Summariz
e
the basic operation using assumptions about the data structure.
---------------------------------------------------------------------
struct FileEntry
{
int m_iDecoder;
struct FileEntry *m_pNext;
struct FileEntry *m_pContents;
struct FileEntry *m_pContainer;
int m_iFCBEntry;
};
RETCODE_reentrant FooBar(struct FileEntry *pEntry)
{
RETCODE rtn=!SUCCESS;
if(g_iTotalTracks<MAX_FILES&&pEntry->m_iDector!=FILE_ENTRY_UNUSED)
{
if(pEntry->m_iDector==FILE_ENTRY_DIR)
{
struct FileEntry *pCurrentEntry=pEntry->m_pContents;
while(pCurrentEntry)
{
FooBar(pCurrentEntry);
pCurrentEntry=pCurrentEntry->m_pNext;
}
}
else
{
g_PlayList[g_iTotalTracks]=pEntry;
g_iTotalTracks++;
}
}
rtn=SUCESS;
}
return rtn;
}
定义一个结构体FileEntry
它有两个数据域
三个指针域
又定义一个函数FooBar
它的返回值类型为RETCODE_reentrant
它的作用向结构体插入一个节点
---------------------------------------------------------
THE END
----------------解决方案--------------------------------------------------------
To:编程女孩
Q6:Modify the above functions,using pointers,so values at the end of
foo() are a=3 and b=4
A6:
这个是正确的
我觉得你对题目的意思理解有误,不是让你判断对错,
它意思是让你修改程序,用上指针,且运行foo()后 a=3 and b=4
----------------解决方案--------------------------------------------------------
***用指针来实现***
void foo()
{
int aa =1,bb =2;
int *a;
int *b;
a =&aa;
b =&bb;
bar(a);
bar(b);
}
void bar(int *p)
{
*p+=2;
}
&&&用引用来实现&&&
void foo()
{
int a =1,b =2;
bar(a);
bar(b);
}
void bar(int &p)
{
p+=2;
}
----------------解决方案--------------------------------------------------------
To:编程女孩
第三题答错了吧?
九到十一要求用纯C写的
十二题没答到点子上(what do you call this type of function?)
----------------解决方案--------------------------------------------------------
最后一题好像是递归生成树,不知对不对?有没有高手给分析一下?
----------------解决方案--------------------------------------------------------
不错
----------------解决方案--------------------------------------------------------
struct FileEntry
{
int m_iDecoder;
struct FileEntry *m_pNext;
struct FileEntry *m_pContents;
struct FileEntry *m_pContainer;
int m_iFCBEntry;
};
RETCODE_reentrant FooBar(struct FileEntry *pEntry)
{
RETCODE rtn=!SUCCESS;
if(g_iTotalTracks<MAX_FILES&&pEntry->m_iDector!=FILE_ENTRY_UNUSED)
{
if(pEntry->m_iDector==FILE_ENTRY_DIR)
{
struct FileEntry *pCurrentEntry=pEntry->m_pContents;
while(pCurrentEntry)
{
FooBar(pCurrentEntry);
pCurrentEntry=pCurrentEntry->m_pNext;
}
}
else
{
g_PlayList[g_iTotalTracks]=pEntry;
g_iTotalTracks++;
}
}
rtn=SUCESS;
}
return rtn;
}
---------------------------------------------------------
THE END
定义一个结构体FileEntry
它有两个数据域(m_iDecoder)( m_iFCBEntry)
三个指针域(FileEntry *m_pNext;)(FileEntry *m_pContents;)(FileEntry *m_pContainer;)这些是文件指针
又定义一个函数FooBar
它的返回值类型为RETCODE_reentrant
它的作用向结构体插入一个节点
这好象不是单纯的C
----------------解决方案--------------------------------------------------------