摘要:
那年还是语言刚入门的我,不知纠结了几多次,才完成了能支持大数的算术四则运算,现在看起来别是一番滋味哈。算术四则运算中就数除法的实现最为繁杂,基本思路按照除法笔算的步骤进行,计算商时一位一位的进行,当计算某一位商时则不断地与除数相减,得到的相减次数作为本位商的结果,实现代码如下,代码可读性不高,效率有待优化,英雄莫见笑。/*
* author:Zhanhang
*
* qq:273711460
* E-mail:zhanxinhang@gmail.com
* HomePage:http://blog.csdn.net/zhanxinhang
*/ #include<stdio.h>
阅读全文
摘要:
#include <stdio.h>
#include <string.h>
struct TStudent
{ long int ID; union{ char name[10]; char mingzi[11]; }; char dept[17];
};
int main()
{ TStudent stu; strcpy(stu.name,"zh"); strcpy(stu.dept,"computer science"); printf("student`s mingzi is:%s\n",stu.min 阅读全文
摘要:
代码:#include <stdio.h>
char* GetString1()
{ char p[] = "Hello World"; return p;
}
char* GetString2()
{ char *p = "Hello World"; return p;
}
int main()
{ printf("GetString1 returns: %s. \n", GetString1()); printf("GetString2 returns: %s. \n", GetString2()) 阅读全文
摘要:
代码:#include <stdio.h>
int main()
{ int a=0,b=0; printf("%d\n",!a||++b||b++); printf("b=%d\n",b); printf("%d\n",!a&&++b&&b++); printf("b=%d\n",b); return 0;
}疑:以上输出什么,为什么?解答:int a=0,b=0;在在第一次printf语句中,!a为1,后面的++b和b++就不做了,所以第二次输出是0,第三次print 阅读全文
摘要:
代码:#include <iostream>
using namespace std;
class A
{
public: A() { Print(); } virtual void Print() { cout<<"A is constructed.\n"; }
}; class B: public A
{
public: B() { Print(); } virtual void Print() { cout<<"B is constructed.\n"; }
}; int main()
{ A* p... 阅读全文
摘要:
代码:头文件print_tools.h#include<stdio.h>
void printStr(const char *pStr)
{ printf("%s\n",pStr);
}
void printtInt(const int i)
{ printf("%d\n",i);
}
头文件counter.h#include"print_tools.h"
static int sg_value;
void counter_init()
{ sg_value=0;
}
void counter_count()
{ sg_v 阅读全文
摘要:
代码:#include<iostream>
using namespace std; class A
{
private: int value;
public: A() { value=0; } void coutHello() { cout<<"hello"<<endl; } void coutValue() { cout<<value<<endl; }
};
int main()
{ A *pA=NULL; //空指针,所指向的内容不可访问存取 pA->coutHello(); pA->coutVa 阅读全文