提交 c1e058a6 创建 作者: 赵鹏翀's avatar 赵鹏翀

init template

上级
/Debug
/Release
<?xml version="1.0" encoding="gb2312"?>
<ASMProject Version="1.00" Name="Lab008" TemplatePath="console(c)\Project" ProjectID="3a728c50-628c-4bc7-ade2-e5ae2de5cece" IsSubmitWork="0">
<Configurations>
<Configuration Name="Debug" DebuggerFlavor="0">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" LanguageStandard="c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
<Configuration Name="Release" DebuggerFlavor="0">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG" LanguageStandard="c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" StripDebugInfo="-1"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="ͷļ" Filter="h;hpp;hxx">
<File RelativePath=".\console.h">
</File>
</Filter>
<Filter Name="Դļ" Filter="cpp;c;cc;cxx">
<File RelativePath=".\console.c">
</File>
</Filter>
</Files>
</ASMProject>
添加文件
#include "console.h"
#include <stdlib.h>
int main(int argc, char* argv[])
{
// C语言程序的机器级表示
case1(); // 过程调用
case2(); // 选择语句if
case3(); // for循环结构
// 复杂数据类型的分配和访问
case4(); // 数组
case5(); // 指针
case6(); // 结构体
case7(); // 联合体
return 0;
}
int sum(int i, int j)
{
int k = i + j; // 加法
return k;
}
void case1()
{
int i = sum(1, 2);
}
void case2()
{
int x, y; // if语句
if(x > y)
y++;
else
x--;
}
void case3()
{ // for循环
int i, sum = 0;
for(i = 0; i < 10; i++)
{
sum = sum + i;
}
}
void case4()
{ // 数组
int i = 1;
int a[4];
a[0] = 6;
a[1] = 7;
a[i + 1] = 8;
}
typedef struct _TreeNode
{
int val;
struct _TreeNode *lchild, *rchild;
}TreeNode;
void case5()
{ // 指针
TreeNode* p = (TreeNode*)malloc(sizeof(TreeNode));
p->lchild = p;
p = p->rchild;
}
// #pragma pack(1) // 通知编译器按照单个字节方式对齐下列结构体中的成员
typedef struct _Rec
{
int i;
char c;
int j;
}Rec;
#pragma pack() // 恢复默认对齐方式
void case6()
{
Rec x; // 结构体
x.j = 1;
x.c = x.j;
x.i = x.j;
}
union var{
char c[4];
int i;
};
void case7()
{ // 联合体
union var data;
data.c[0] = 0x04; // 在内存中的内容是由低到高04 03 02 11
data.c[1] = 0x03;
data.c[2] = 0x02;
data.c[3] = 0x11;
printf("%x\n", data.i); // 输出结果是11020304,所以可以看出是小端模式
}
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#include <stdio.h>
/* TODO: 在此处引用程序需要的其他头文件 */
void case1();
void case2();
void case3();
void case4();
void case5();
void case6();
void case7();
int add(int i, int j);
#endif /* _CONSOLE_H_ */
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论