1.什么是分布式数据库?

分布式数据库是用计算机网络将物理上分散的多个数据库单元连接起来组成的一个逻辑上统一的数据库。每个被连接起来的数据库单元称为站点或节点。分布式数据库有一个统一的数据库管理系统来进行管理,称为分布式数据库管理系统。分布式数据库的基本特点包括:物理分布性、逻辑整体性和站点自治性。从这三个基本特点还可以导出的其它特点有:数据分布透明性、按既定协议达成共识的机制、适当的数据冗余度和事务管理的分布性。

2.设有“int w[3][4];”,pw是与数组名w等价的数组指针,则pw的初始化语句为 int *pw = w;

  要使引用pr代表变量“char *p”,则pr的初始化语句为 char &pr = *p;

3.写一段代码判断一个单向链表中是否有环

#include <iostream>
using namespace std;
struct node
{
      int data;
      struct node *next;
}*linklist,*s,*head;
bool IsLoop(node *head)
{
      node *pSlow=head;
      node *pFast=head;
      while(pSlow!=NULL && pFast!=NULL)
      {
            pSlow=pSlow->next;
            pFast=pFast->next->next;
            if(pSlow==pFast)
                 return true;
      }
      return false;
}
node* InsertNode(node *head,int value)
{
      if(head==NULL)
      {
            head=(node *)malloc(sizeof(node));
            if(head==NULL)
                  printf("malloc failed");
            else
            {
                  head->data=value;
                  head->next=NULL;
            }
       }
       else
       {
            node *temp=(node *)malloc(sizeof(node));
            if(temp==NULL)
                  printf("malloc failed");
            else
            {
                  temp->data=value;
                  temp->next=head;
                  head=temp;
             }
       }
       return head;
}
int main(void)
{
       node *t,*q,*p=NULL;
       p=InsertNode(p,8);
       p=InsertNode(p,7);
       p=InsertNode(p,6);
       p=InsertNode(p,5);
       p=InsertNode(p,4);
       q=p;
       p=InsertNode(p,3);
       p=InsertNode(p,2);
       p=InsertNode(p,1);
       t=p;
       while(t->next)       // 找到链表的尾指针
              t=t->next;
       t->next=q;           // 将链表的尾指针指向第四个节点,这样就构成了一个环
       bool flag=IsLoop(p);
       if(flag)
             cout<<"这个链表存在一个环"<<endl;
       else
             cout<<"这个链表不存在一个环"<<endl;
       system("pause");
       return 0;
}



4.指针之间可以相减,但不可以相加:两个同一类型的指针变量是可以相减的,他们的意义表示两个指针指向的内存位置之间相隔多少个元素(注意是元素,并不是字节数),例如对于int类型的指针p和p1. p1-p的意义表示他们之间相隔多少个int类型的元素。同样对于其他类型的指针变量之间相减的意义也是一样。 指针变量的自加和自减实际上是与整数1的加减运算。指针之间可以比较大小。但是同样也限于两个相同类型的指针变量,不同类型的指针变量之间比较大小没有任何意义。指针之间的大小比较的意义,表示在内存中他们指向的位置的高低关系。

5.以下两种方法功能一致,实现方法不一样而已

char *GetMemory()
{ 
  char *p=(char *)malloc(100); 
  return p; 
} 
int main(void)
{ 
  char *str=NULL; 
  str=GetMemory();
  strcpy(str,"hello world"); 
  printf(str); 
}

void GetMemory2(char **p, int num) 
{ 
*p = (char *)malloc(sizeof(char) * num); 
} 
int main(void)
{ 
  char *str=NULL; 
  GetMemory=(&str); 
  strcpy(str,"hello world"); 
  printf(str); 
}

6.

一:
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
        char str[10];

        cout << "input:";
        cin >> str;
        cout << "cin:" << str << endl;

        return 0;
}
输出:
[root@localhost test]# ./a.out 
input:I love this game
cin:I 

二:
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
        char str[10];

        cout << "input:";
        cin.get(str, 10);
        cout << "cin.get():" << str << endl;

        return 0;
}
输出:
[root@localhost test]# ./a.out 
input:I love this game
cin.get():I love th

三:
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
        char str[10];

        cout << "input:";
        cin.getline(str, 10);
        cout << "cin.getline():" << str << endl;

        return 0;
}
输出:
[root@localhost test]# ./a.out 
input:I love this game
cin.getline():I love th
第一种情况是因为:cin 用来接收字符串的时候,遇“空格”“TAB” “回车”时都会结束。第二,三种里面的函数可以用来接收带空格的字符串并输出空格。输出结果不完整是因为字符串分配的空间不够,输出 "I love th" , 里面有7个字符两个空格,共九个字节,第十个字节存的是'\0'.想得到完整的字符串,只需把str的空间在增大一些即可。