PC-lint测试C/C++实例
实例1:test.cpp
1 #include
2 class X
3 {
4 int *p;
5 public:
6 X()
7 { p = new int[20]; }
8 void init()
9 { memset( p, 20, 'a' ); }
10 ~X()
11 { delete p; }
12 };
编译这个文件,VC6.0产生0 errors 0 warnings, 而lint程序产生了如下8条警告信息,有些还是很有用处的提示。
PC-lint 告警信息:
test.cpp(12): error 783: (Info -- Line does not end with new-line)
test.cpp(7): error 1732: (Info -- new in constructor for class 'X' which has no assignment operator)
test.cpp(7): error 1733: (Info -- new in constructor for class 'X' which has no copy constructor) { memset( p, 20, 'a' ); }
test.cpp(9): error 669: (Warning -- Possible data overrun for function 'memset(void *, int, unsigned int)', argument 3 (size=97) exceeds argument 1 (size=80) [Reference: test.cpp: lines 7, 9])
test.cpp(7): error 831: (Info -- Reference cited in prior message)
test.cpp(9): error 831: (Info -- Reference cited in prior message)
{ delete p; }
test.cpp(11): error 424: (Warning -- Inappropriate deallocation (delete) for 'new[]' data)
--- Wrap-up for Module: test.cpp
test.cpp(2): error 753: (Info -- local class 'X' (line 2, file test.cpp) not referenced)
error 900: (Note -- Successful completion,8 messages produced)
根据错误提示修改后的程序如下:
#include
class X /*lint -e753 *///只声明实现类X,没有写main()应用类x,故可以屏蔽。
{
int *p;
public:
X() //构造函数
{
p = NULL;
}
X (const X &x) //拷贝构造函数
{
p = new int[20];
memcpy(p, x.p, 20*sizeof(int));
}
X & operator= (const X &x) //赋值操作符
{
if (this == &x) //检查自赋值
{
return *this;
}
int *temp = new int[20];
memcpy(temp, x.p, 20*sizeof(int)); //复制指针指向内容
delete []p; //删除原有指针(将删除操作符放在后面,避免X=X特殊情况下,内容的丢失)
p=temp; //建立新指向
return *this;
}
void init()
{
if (NULL == p) return; // 判断指针是否为空
memset( p, 'a', 20*sizeof(int));
}
~X()
{
delete []p;
}
};
//在};后面回车换行以消除告警test.cpp(12): error 783: (Info -- Line does not end with new-line) 注意:为需要动态分配内存的类声明一个拷贝构造函数和一个赋值操作符(可参考effective_c++2e 条款11)
再次运行pclint
PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008
--- Module: test.cpp (C++)
--- Global Wrap-up
error 900: (Note -- Successful completion, 0 messages produced)
实例2:实现输入的两个复数的四则运算。
/****************************************
File name:Complex.h
Function:A simple complex calculator demo
****************************************/
#include
using namespace std;
class complex
{
public: // public interface
complex(double r, double i); // constructor
void assign(void); // user input to define a complex
// overload operators to friend functions friend complex operator + (complex &c1, complex &c2);
friend complex operator - (complex &c1, complex &c2);
friend complex operator * (complex &c1, complex &c2);
friend complex operator / (complex &c1, complex &c2);
friend ostream& operator << (ostream &out, complex x);
private:
double real;
double imag;
};
/****************************************
File name:Complex.cpp
Function:A simple complex calculator demo
****************************************/
#include"Complex.h"
complex::complex(double r = 0.0, double i = 0.0)
{
real = r;
imag = i;
return;
}
void complex::assign(void)
{
cout << "Please input the real part : " << endl;
cin >> real;
cout << "Please input the imaginary part: " << endl;
cin >> imag;
return;
}
ostream& operator << (ostream &out, complex x)
{
if (x.imag < 0)
{
return (out << x.real << " + " << "(" << x.imag << ")" << "i" << endl);
}
else
{
return (out << x.real << " + " << x.imag << "i" << endl);
}
}
complex operator + (complex &c1, complex &c2)
{
return complex(c1.real + c2.real, c1.imag + c2.imag);
}
complex operator - (complex &c1, complex &c2)
{
return complex(c1.real - c2.real, c1.imag - c2.imag);
}
complex operator * (complex &c1, complex &c2)
{
return complex((c1.real * c2.real - c1.imag * c2.imag) ,(c1.real * c2. imag + c2.real *
c1.imag));
}
complex operator / (complex &c1, complex &c2)
{
double denominator = c2.real * c2.real + c2.imag * c2.imag;
return complex((c1.real * c2.real + c1.imag * c2.imag) / denominator ,(c1.imag * c2.real - c1.real * c2.imag) / denominator);
}
int main(void)
{
complex c1(5, 4), c2(2, 10);
cout << "c1 = " << c1;
cout << "c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
cout <<"c1 / c2 = " << c1 / c2;
c1.assign();
cout << "Current c1 = " << c1;
c2.assign();
cout << "Current c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
cout <<"c1 / c2 = " << c1 / c2;
return 0;
}
编译这两个文件,VC6.0编译器产生0 errors 0 warnings, 而pclint程序产生了如下27条警告信息, PC-lint 告警信息如下:
PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008
--- Module: Bcomplex.cpp (C++)
};
Bcomplex.h(19): error 783: (Info -- Line does not end with new-line)
Bcomplex.h(19): error 1712: (Info -- default constructor not defined for class 'complex')
}
Bcomplex.cpp(30): error 1746: (Info -- parameter 'x' in function
'operator<<(std::basic_ostream
Bcomplex.cpp(35): error 1764: (Info -- Reference parameter 'c1' (line 32) could be declared const ref) Bcomplex.cpp(32): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(35): error 1764: (Info -- Reference parameter 'c2' (line 32) could be declared const ref) Bcomplex.cpp(32): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(40): error 1764: (Info -- Reference parameter 'c1' (line 37) could be declared const ref) Bcomplex.cpp(37): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(40): error 1764: (Info -- Reference parameter 'c2' (line 37) could be declared const ref) Bcomplex.cpp(37): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(45): error 1764: (Info -- Reference parameter 'c1' (line 42) could be declared const ref) Bcomplex.cpp(42): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(45): error 1764: (Info -- Reference parameter 'c2' (line 42) could be declared const ref) Bcomplex.cpp(42): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(51): error 1764: (Info -- Reference parameter 'c1' (line 47) could be declared const ref) Bcomplex.cpp(47): error 830: (Info -- Location cited in prior message)
}
Bcomplex.cpp(51): error 1764: (Info -- Reference parameter 'c2' (line 47) could be declared const ref) Bcomplex.cpp(47): error 830: (Info -- Location cited in prior message)
complex c1(5, 4), c2(2, 10);
Bcomplex.cpp(55): error 747: (Info -- Significant prototype coercion (arg. no. 1) int to double) Bcomplex.cpp(55): error 747: (Info -- Significant prototype coercion (arg. no. 2) int to double) Bcomplex.cpp(55): error 747: (Info -- Significant prototype coercion (arg. no. 1) int to double) Bcomplex.cpp(55): error 747: (Info -- Significant prototype coercion (arg. no. 2) int to double)
--- Global Wrap-up
error 1754: (Info -- Expected symbol 'operator*=' to be declared for class 'complex')
error 1754: (Info -- Expected symbol 'operator+=' to be declared for class 'complex') error 1754: (Info -- Expected symbol 'operator-=' to be declared for class 'complex') error 1754: (Info -- Expected symbol 'operator/=' to be declared for class 'complex') error 900: (Note -- Successful completion, 27 messages produced)
根据提示修改代码如下:
/****************************************
File name:Complex.h
Function:A simple complex calculator demo
****************************************/
#include
using namespace std;
class complex
{
public: // public interface
complex(void); // void constructor
complex(double r, double i); // constructor
void assign(void); // user input to define a complex
// overload operators to friend functions friend complex operator + (const complex &c1, const complex &c2);
friend complex operator - (const complex &c1, const complex &c2);
friend complex operator * (const complex &c1, const complex &c2);
friend complex operator / (const complex &c1, const complex &c2);
friend ostream& operator << (ostream &out, const complex &x);
private:
double real;
double imag;
};
/****************************************
File name:Complex.cpp
Function:A simple complex calculator demo
****************************************/
#include"Complex.h"
complex::complex(void)
{
real = 0;
imag = 0;
return;
}
complex::complex(double r = 0.0, double i = 0.0)
{
real = r;
imag = i;
return;
}
void complex::assign(void)
{
cout << "Please input the real part : " << endl;
cin >> real;
cout << "Please input the imaginary part: " << endl;
cin >> imag;
return;
}
ostream& operator << (ostream &out, const complex &x)
{
if (x.imag < 0)
{
return (out << x.real << " + " << "(" << x.imag << ")" << "i" << endl);
}
else
{
return (out << x.real << " + " << x.imag << "i" << endl);
}
}
complex operator + (const complex &c1, const complex &c2)
{
return complex(c1.real + c2.real, c1.imag + c2.imag);
}
complex operator - (const complex &c1, const complex &c2)
{
return complex(c1.real - c2.real, c1.imag - c2.imag);
}
complex operator * (const complex &c1, const complex &c2)
{
return complex((c1.real * c2.real - c1.imag * c2.imag),(c1.real * c2. imag + c2.real * c1.imag)); }
complex operator / (const complex &c1, const complex &c2)
{
double denominator = c2.real * c2.real + c2.imag * c2.imag;
return complex((c1.real * c2.real + c1.imag * c2.imag) / denominator,(c1.imag * c2.real -
c1.real * c2.imag) / denominator);
}
int main(void)
{
complex c1(5.0, 4.0), c2(2.0, 10.0);
cout << "c1 = " << c1;
cout << "c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
cout <<"c1 / c2 = " << c1 / c2;
c1.assign();
cout << "Current c1 = " << c1;
c2.assign();
cout << "Current c2 = " << c2;
cout << "c1 + c2 = " << c1 + c2;
cout << "c1 - c2 = " << c1 - c2;
cout << "c1 * c2 = " << c1 * c2;
cout <<"c1 / c2 = " << c1 / c2;
return 0;
}
再次运行pclint,信息如下:
PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008
--- Module: Complex.cpp (C++)
--- Global Wrap-up
error 1754: (Info -- Expected symbol 'operator*=' to be declared for class 'complex')
error 1754: (Info -- Expected symbol 'operator+=' to be declared for class 'complex')
error 1754: (Info -- Expected symbol 'operator-=' to be declared for class 'complex')
error 1754: (Info -- Expected symbol 'operator/=' to be declared for class 'complex')
error 900: (Note -- Successful completion, 4 messages produced)
编号1754信息:如果类中出现重载操作符时(operator op,op为+、-、*、/),pclint建议声明相应的重载赋值操作符,这里不声明也没问题。可以用/*lint -e1754*/进行屏蔽。参看参看PC-Lint目录下的msg.txt文件,里面有详细的解释。
实例3:PC-lint通过检查下面的代码可以发现比其他的C语言编译器发现更多的问题,包括其中的错误和潜在的问题。
1:
2:char *report( int m, int n, char *p )
3:{
4:int result;
5:char *temp;
6:long nm;
7:int i, k, kk;
8:char name[11] = "Joe Jakeson"; //error 784 向name数组赋值时丢掉了结尾的nul字符
9:
10:nm = n * m;
11:temp = p == "" ? "null" : p; // error 779字符串常量不能用于”==”操作符
12:for( i = 0; i 14:k++; // error 530 k没有被初始化 15:kk = i; // error 771 kk可能没有被初始化 16:} 17: 18:if( k== 1 ) result = nm; 19:else if( kk > 0 ) result = 1; 20:else if( kk < 0 ) result = -1; 21: 22:if( m == result ) return( temp ); // error 644 result也有可能没有被初始化 23:else return( name ); // error 604 返回的是一个局部对象name的地址 24:} // error 783 没有以新一行结束 PC-lint检查信息如下: PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008 --- Module: test.cpp (C++) char name[11] = "Joe Jakeson"; test.cpp(8): error 784: (Info -- Nul character truncated from string) temp = p == "" ? "null" : p; test.cpp(10): error 779: (Info -- String constant in comparison operator '==') test.cpp(5): error 830: (Info -- Location cited in prior message) for( i = 0; i test.cpp(11): error 40: (Error -- Undeclared identifier 'I') test.cpp(11): error 52: (Error -- Expected an lvalue) k++; test.cpp(13): error 530: (Warning -- Symbol 'k' (line 7) not initialized) test.cpp(7): error 830: (Info -- Location cited in prior message) else if( kk > 0 ) result = 1; test.cpp(18): error 771: (Info -- Symbol 'kk' (line 7) conceivably not initialized) test.cpp(7): error 830: (Info -- Location cited in prior message) if( m == result ) test.cpp(21): error 644: (Warning -- Variable 'result' (line 4) may not have been initialized) test.cpp(4): error 830: (Info -- Location cited in prior message) return( name ); test.cpp(24): error 604: (Warning -- Returning address of auto variable 'name') } test.cpp(25): error 783: (Info -- Line does not end with new-line) --- Global Wrap-up error 900: (Note -- Successful completion, 14 messages produced) 实例4: #include void find(char arg) { switch(arg) { case'a': printf("a\n"); //没有break,可以用注释//lint –fallthrough消除告警825 case'b': printf("b\n"); //同上 case'c': printf("c\n"); //case控制流一直没被break中断直接进入最后一个case或 //defult,可以用/* fall through */消除告警616 } //没有default语句 } int main(int argc, char* argv[]) //参数argc和argv没有被引用 { char buff[3] = {'a', 'b', 'c'}; int i = 0; while(1) //while(1)的问题,请使用for(;;)替代 { find(buff[i]); printf("\n"); ++i ; //++i使数组越界 } printf("OK!\n"); //程序不会被执行到的地方 return 0; } 编译这个文件,VC6.0编译器产生0 errors 0 warnings, 而pclint程序产生了如下14条警告信息, PC-lint 告警信息如下:可见,在这里数组越界pclint同样没有检查出来。 PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008 --- Module: test.cpp (C++) case 'b': test.cpp(8): error 616: (Warning -- control flows into case/default) test.cpp(8): error 825: (Info -- control flows into case/default without -fallthrough comment) case 'c': test.cpp(10): error 616: (Warning -- control flows into case/default) test.cpp(10): error 825: (Info -- control flows into case/default without -fallthrough comment)} test.cpp(12): error 744: (Info -- switch statement has no default) while(1) test.cpp(18): error 716: (Info -- while(1) ... ) printf("OK!\n"); test.cpp(23): error 527: (Warning -- Unreachable code at token 'printf') } test.cpp(25): error 783: (Info -- Line does not end with new-line) test.cpp(25): error 715: (Info -- Symbol 'argv' (line 14) not referenced) test.cpp(14): error 830: (Info -- Location cited in prior message) } test.cpp(25): error 818: (Info -- Pointer parameter 'argv' (line 14) could be declared as pointing to const) test.cpp(14): error 830: (Info -- Location cited in prior message) } test.cpp(25): error 715: (Info -- Symbol 'argc' (line 14) not referenced) test.cpp(14): error 830: (Info -- Location cited in prior message) --- Global Wrap-up error 900: (Note -- Successful completion, 14 messages produced) 根据提示修改代码如下: #include void find(char arg) { switch(arg) { case'a': printf("a\n");//lint –fallthrough case'b': printf("b\n");//lint –fallthrough case'c': printf("c\n");break; default: printf("OK\n"); } } int main(int argc, char* argv[]) { (void)argc; // pclint (void)argv; // pclint char buff[3] = {'a', 'b', 'c'}; int i = 0; for(;;) { find(buff[i]); printf("\n"); if(++i > 2) break ; } printf("OK!\n"); return 0; }再次运行PClint就没有告警。 实例5: #include #include using namespace std; //定义公共基类Person class Person {public: Person(char *nam,char s,int a) //构造函数 {strcpy(name,nam);sex=s;age=a;} protected: //保护成员 char name[20]; char sex; int age; }; //定义类Teacher class Teacher:virtual public Person //声明Person为公用继承的虚基类 {public: Teacher(char *nam,char s,int a,char *t):Person(nam,s,a) //构造函数 {strcpy(title,t); } protected: //保护成员 char title[10]; //职称 }; //定义类Student class Student:virtual public Person //声明Person为公用继承的虚基类 {public: Student(char *nam,char s,int a,float sco): //构造函数 Person(nam,s,a),score(sco){} //初始化表 protected: //保护成员 float score; //成绩 }; //定义多重继承的派生类Graduate class Graduate:public Teacher,public Student //声明Teacher和Student类为公用继承的直接基类 {public: Graduate(char *nam,char s,int a,char *t,float sco,float w): //构造函数 Person(nam,s,a),Teacher(nam,s,a,t),Student(nam,s,a,sco),wage(w){} //初始化表void show( ) //输出研究生的有关数据 {cout<<"name:"< cout<<"age:"< cout<<"sex:"< cout<<"score:"< cout<<"title:"< cout<<"wages:"< } private: float wage; //工资 }; int main( ) {Graduate grad1("Wang-li",'f',24,"assistant",89.5,1234.5); grad1.show( ); return 0; } 编译这个文件,VC6.0编译器产生0 errors 0 warnings, 而pclint程序产生了如下14条警告信息, PC-lint 告警信息如下: PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008 --- Module: test.cpp (C++) {strcpy(name,nam);sex=s;age=a;} test.cpp(8): error 818: (Info -- Pointer parameter 'nam' (line 7) could be declared as pointing to const) test.cpp(7): error 830: (Info -- Location cited in prior message) }; test.cpp(13): error 1712: (Info -- default constructor not defined for class 'Person') {public: test.cpp(16): error 1790: (Info -- Base class 'Person' has no non-destructor virtual functions) } test.cpp(19): error 818: (Info -- Pointer parameter 't' (line 17) could be declared as pointing to const) test.cpp(17): error 830: (Info -- Location cited in prior message) }; test.cpp(22): error 1712: (Info -- default constructor not defined for class 'Teacher') {public: test.cpp(25): error 1790: (Info -- Base class 'Person' has no non-destructor virtual functions) }; test.cpp(30): error 1712: (Info -- default constructor not defined for class 'Student') class Graduate:public Teacher,public Student test.cpp(32): error 1790: (Info -- Base class 'Teacher' has no non-destructor virtual functions) {public: test.cpp(33): error 1790: (Info -- Base class 'Student' has no non-destructor virtual functions) }; test.cpp(46): error 1712: (Info -- default constructor not defined for class 'Graduate') {Graduate grad1("Wang-li",'f',24,"assistant",89.5,1234.5); test.cpp(49): error 1776: (Info -- Converting a string literal to char * is not const safe (arg. no. 1)) test.cpp(49): error 1776: (Info -- Converting a string literal to char * is not const safe (arg. no. 4)) test.cpp(49): error 747: (Info -- Significant prototype coercion (arg. no. 5) double to float) test.cpp(49): error 747: (Info -- Significant prototype coercion (arg. no. 6) double to float) } test.cpp(52): error 783: (Info -- Line does not end with new-line) --- Wrap-up for Module: test.cpp } test.cpp(53): error 766: (Info -- Header file 'D:\Program Files\Microsoft Visual Studio 9.0\VC\include\string' not used in module 'test.cpp') --- Global Wrap-up error 900: (Note -- Successful completion, 18 messages produced) 根据提示修改代码如下: #include using namespace std; //定义公共基类Person class Person {public: Person() { memset(name,'\0',sizeof(name)); sex = '\0'; age = 0; } Person(const char *nam,char s,int a) //构造函数 {strcpy(name,nam);sex=s;age=a;} virtual void show() = 0; virtual ~Person(){}; protected: //保护成员 char name[20]; char sex; int age; }; //定义类Teacher class Teacher:virtual public Person //声明Person为公用继承的虚基类 {public: Teacher() { memset(title,'\0',sizeof(title)); } Teacher(const char *nam,char s,int a,const char *t):Person(nam,s,a) //构造函数 {strcpy(title,t); } protected: //保护成员 char title[10]; //职称 }; //定义类Student class Student:virtual public Person //声明Person为公用继承的虚基类 {public: Student() { score = 0.0; } Student(const char *nam,char s,int a,double sco): //构造函数 Person(nam,s,a),score(sco){} //初始化表 protected: //保护成员 double score; //成绩 }; //定义多重继承的派生类Graduate class Graduate:public Teacher,public Student //声明Teacher和Student类为公用继承的直接基类 {public: Graduate() { wage = 0.0; } Graduate( const char *nam,char s,int a,const char *t,double sco,double w): //构造函数 Person(nam,s,a),Teacher(nam,s,a,t),Student(nam,s,a,sco),wage(w){} //初始化表void show( ) //输出研究生的有关数据 {cout<<"name:"< cout<<"age:"< cout<<"sex:"< cout<<"score:"< cout<<"title:"< cout<<"wages:"< } private: double wage; //工资 }; int main( ) {Graduate grad1("Wang-li",'f',24,"assistant",89.5,1234.5); grad1.show( ); return 0; } 再次运行pclint。 PC-lint for C/C++ (NT) Vers. 9.00a, Copyright Gimpel Software 1985-2008 --- Module: test.cpp (C++) --- Wrap-up for Module: test.cpp test.cpp(14): error 754: (Info -- local structure member 'Person::show(void)' (line 14, file test.cpp) not referenced) --- Global Wrap-up error 900: (Note -- Successful completion, 1 messages produced) 实验一上机操作初步(2学时) 一、实验方式:一人一机 二、实验目的: 1、熟悉VC++语言的上机环境及上机操作过程。 2、了解如何编辑、编译、连接和运行一个C程序。 3、初步了解C程序的特点。 三、实验内容:说明:前三题为必做题目,后两题为选做题目。 1、输出入下信息:(实验指导书P3) ************************* Very Good ************************* 2、计算两个整数的和与积。(实验指导书P4) 3、从键盘输入一个角度的弧度值x,计算该角度的余弦值,将计算结果输出到屏幕。(书 P4) 4、在屏幕上显示一个文字菜单模样的图案: ================================= 1 输入数据 2 修改数据 3 查询数据 4 打印数据 ================================= 5、从键盘上输入两个整数,交换这两个整数。 四、实验答案:(代码+运行结果截屏) #include #include 一、选择题 1. 在每个C 程序中都必须包含有这样一个函数,该函数的函数名为 。 A. main B. MAIN C. name D. function 2. 在以下关于C 语言的注释的叙述中,不正确的是 。 A .注释可用"/*"、"*/"形式表示,也可用"//"形式表示 B .编译器在编译一个程序时,将跳过注释,不对其进行处理 C .编译器在编译一个程序时,可发现注释中的单词拼写错误 D .程序中注释的多少不会影响所生成的可执行文件的长度 3. 以下叙述不正确的是 。 A .在C 程序中,严格区分大小写字母 B .一个C 源程序有且仅有一个main 函数 C .在C 程序中,注释只能位于一条语句的后面 D .一个C 程序总是从main 函数开始执行 4. 下列合法的标识符为 A. abde+ B. #KDJF C. 67KDJ D. DK3_ 5. 关于字符串和字符的关系正确的是 A. “A ”与’A ’是相同的 B. 字符串是常量,字符是变量 C. “A ”与’A ’是不同的 D. “A ”与“A ”是相同的 6. 下面关于语句的说法正确的是 A. 下面这两段程序的执行效果是一致的 B. 空语句是只有一个分号的语句,它其实什么也不干 C. 语句的构成不一定需要分号 D. 语句的书写对程序的运行不起作用,因此可以随便写都可以 7. 以下各标识符中,合法的用户标识符组为 。 A. PAd ,P#d ,b-b ,abc ,_0123,ssiped B. cin ,a10,CPP ,float ,del_word ,signed C. void ,max ,hiy , C语言测试题 姓名:日期:◆下面的测试题中,认为所有必须的头文件都已经正确的包含了◆数据类型 char 一个字节1 byte int 两个字节2 byte long int 四个字节4 byte float 四个字节4 byet double 八个字节8 byte long double 十个字节10 byte pointer 两个字节2 byte 第一题: main() { char *p,*q; char str[]="Hello,World\n"; q = p = str; p++; printf(q); printf(p); } 运行结果是什么?____________ 第二题: void fun(char* str1, char* str2) { static char buffer[21]; strncpy(buffer, str1, 10); strncat(buffer, str2, 10); *str1 = *str2; str1 = buffer; } main() { char str1[] = "ABC\n"; char str2[] = "BCD\n"; fun(str1, str2); printf(str1); printf(str2); } 程序运行结果是__________________ 第三题: main() { short ar[11]={1,2,3,4,5,6,7,8,9,0,11}; short* par=&ar[1]; int i; for(i=0; i<10; i++) { printf("%-5hd%-5hd%-5hd", ar[i], par[i],*(ar+i)); } } 程序运行结果是__________________ 第四题: main() { short *p, *q; short ar[10]={0}; p = q = ar; p++; printf("%5d", p-q); printf("%5d", (char*)p - (char*)q); printf("%5d", sizeof(ar)/sizeof(*ar)); } 假设sizeof(short)==2 程序运行结果是__________________ 第五题: int sub(int a, int b) { return a-b; } 1.若x为int型变量,则执行以下语句后,x的值为-60。 x=6; x+=x-=x*x; x=x-x*x=-30 x=x+x=-60 2.若有定义int a[2][3]; 则对a数组的第i行第j列元素地址的正确引用为a[i]+j。 3.若有说明:int i, j=2,*p=&i;,则能完成i=j赋值功能的语句是*p=*&j。 4.以下叙述正确的是define和if都不能定义为用户标识符。 5. 以下程序的输出结果是2。 #define SQR(X) X*X main() { int a=16, k=2, m=1; a/=SQR(k+m)/SQR(k+m); a/=k+k*m+m/k+k*m+m printf("%d\n",a); } 6. 以下程序的输出结果是4。 main() {int b[3][3]={0,1,2,0,1,2,0,1,2},i,j,t=1; for(i=0;i<3;i++) for(j=i;j<=i;j++) for(j=i;j<=i;j++) t=t+b[i][j]; { t=t+b[i][j];} printf("%d\n",t); printf("%d\n",t); }_ 7. 编一个程序,打入星期号,输出该星期的英文名字。例如,输入"1"则输出"Monday",说明:星期日编号为0,要求用指针数组处理。 main() { char *name[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday"}; int n; printf("\nInput the number(0-6):"); scanf("%d", &n); if ((n< 7) && (n>=0)) printf("\nThe name is: %s",name[n]); else printf("\nInput error"); } 8. 局部变量是静态存储变量。错误 9. "文件包含"处理是指一个源文件可以将另一个源文件的内容全部包含进来。正确 10. 若有定义:int *p1,*p2;则p1+p2无实际意义。正确 11. 若在函数内定义形参数组a:int a[3][4];则数组a中各元素可在程序的编译阶段得到初值0。错误 12. 以下不能正确定义二维数组的选项是int a[2][]={{1,2},{3,4}};。 13. 以下程序的输出结果是6 15 15。 int d=1; fun(int p) { static int d=5; d+=p; printf("%d ",d); return(d); } main( ) { int a=3; printf("%d \n", fun(a+fun(d))); } 一、选择题 以下表达式中非法的是_______ A. 0<=x<=10 B. i=j==0 C. (char)(65+3) D. x+1=x+1 设有int x=10,y=10; 表达式x&&x-y || x+y 的结果为_______ A.20 B. 10 C. 0 D. 1 若有int x=3;执行语句if(x) x=x+3;else x=x-3; 后,变量x的值为_____ A. 3 B. 6 C. 0 D. 该语句有语法错误 若有定义int x=3; 执行语句while(x>=0) x-- ; 后,变量x的值为_______ A. 3 B. 0 C. -1 D. 2 若有定义int x=3若有定义char st[20]= "abc\ndef"; 则函数strlen(st)的值为_______ A.20 B.8 C.9 D.7; 在函数调用语句fun((x1,x2),(x3,x4,x5))中的实参的个数是_______ A. 1 B. 2 C.3 D. 4 数组初始化为:int a[10]={1,3,5,7}; 则数组元素a[4]的值为_______ A. 0 B. 7 C. 不确定 D. 1 若有定义int x,*p; 能为变量p正确赋值的表达式为________ A. p=x B. p=*x C. p=&x D. *p=x 若有定义struct sk{int a;float b}data; int *p;若要使p指向data中的成员a,正确 的赋值语句为_______________ A.p=&a; B.p=data.a; C.p=&data.a; D.*p=data.a C语言程序语句的分割符,也就是一条语句的结束符是( )。 A.逗号 B.句号 C.分号 D.括号 字符型变量输入、输出的格式是( )。 A.%d b.%f C.%c d.%s 下面求梯形面积的C语句中变量a,b,h,s是float型,不正确的是( )。 a.s=1/2*(a+b)*h B.s=1.0/2*(a+b)*h C.s=1/2.0*(a+b)*h D.s=(a+b)*h/2 While和do/while二种循环语句可能的最少的循环次数分别是( )。 A.0次和0次 B.0次和1次 C.1次和0次 D.1次和1次 说明char a[10]中定义了( )。 A.a[1]至a[10]共10个变量 B.a[1]至a[9]共9个变量 C.a[0]至a[10]共11个变量 D.a[0]至a[9]共10个变量 ** 课程代码:A100002座位号: 《计算机技术基础(C语言)》试卷A 姓名: 学号: 专业: 学院: 班级: 20 年月日 第一部分选择题(共 30 分) 一、单项选择题(本大题共 15 小题,每题只有一个 正确答案,答对一题得 2 分,共 30 分) 1、以下关于C语言标识符的描述中,正确的是【】。A)标识符可以由汉字组成B)标识符只能以字母开头 C)关键字可以作为用户标识符D)Area与area是不同的标识符2、使下列程序段输出“123,456,78”,键盘输入数据,正确的输入是【】。 int i,j,k; scanf(“%d,%3d%d”,&i,&j,&k); printf(“%d,%d,%d\n”,i,j,k); A)12345678 B)123,456,78 C)123,45678 D)123,*45678 3、判断char类型的变量c1是否为数字字符的正确表达式为【】。 A) (c1>=0)&&(c1<=9) B) (c1>=’0’)&&(c1<=’9’) C) ’0’<=c1<=’9’ D) (c1>=’0’)||(c1<=’9’) 4、若有语句int a=1,b=2,c=3;则以下值为0的表达式是【】。A)’a’&&’b’ B)a<=b C)((a>b)||(b 【】 A. *(a[0]+2) B. a[1][3] C . a[1][0] D. *(*(a+1)+2) 6、在循环语句的循环体中执行break语句,其作用是【】。A)跳出该循环体,提前结束循环 B)继续执行break语句之后的循环体各语句 C)结束本次循环,进行下次循环 D)终止程序运行 7、执行语句for(i=10;i>0;i--);后,变量i的值为【】。A)10 B)9 C)0 D)1 8、若有int *p1, *p2,k; 不正确的语句是【】 A. p1=&k B. p2=p1 C. *p1=k+12 D. k=p1+p2 9、在函数中未指定存储类别的局部变量,其隐含的存储类别是【】 A. 静态(static) B. 外部(extern) C. 自动(auto)D. 寄存器(register) 10、如下程序的输出结果是【】 main( ) { int x=2,a=0,b=0; switch(x) { case 2: a++; b++; case 1: ++a; b--; break; case 0: b++;} printf("a=%d, b=%d\n", a, b);} A. a=2, b=0 B. a=2, b=1 C. a=1, b=1 D. a=1, b=0 11、表示关系a main() {int x; scanf(“%d”,&x); if(x<=3) ; else if(x !=10)printf(“%d\n”,x); } 计算机技术基础试题第2页(共11页) 六 ━━━━━━━━━━━━━━━ 一、判断共10题(共计20分) ━━━━━━━━━━━━━━━ 第1题(2.0分)题号:1259 若定义int m[]={1,2,3,4,5};则m[1]的值为2. 答案:Y 第2题(2.0分)题号:1275 如果定义一个函数时省略类型,则函数没有返回值. 答案:N 第3题(2.0分)题号:12 结构体类型只有一种。 答案:N 第4题(2.0分)题号:1241 在C语言的标识符中,大写字母和小写字母完全等价. 答案: 第5题(2.0分)题号:1271 定义一种结构体类型后,则用该类型定义的所有变量占用内存的大小是相同的. 答案:Y 第6题(2.0分)题号:1269 若定义int a[4]={1,2,3,4};若超界引用a[4]则编译时不报错. 答案:Y 第7题(2.0分)题号:1096 C语言中"%"运算符的运算对象必须是整型. 答案:Y 第8题(2.0分)题号:1109 两个字符串中的字符个数相同时才能进行字符 串大小的比较 答案:N 第9题(2.0分)题号:1135 语句printf("%c",65);存在语法错误. 答案:N 第10题(2.0分)题号:32 若有说明int c;则while(c=getchar());是正 确的C语句。 答案:Y ━━━━━━━━━━━━━━━━━ 二、单项选择共15题(共计30分) ━━━━━━━━━━━━━━━━━ 第1题(2.0分)题号:3114 C语言源程序名的后缀是 A:exe B:c C:obj D:cp 答案:B 第2题(2.0分)题号:184 以下不能正确定义二维数组的选项是 ( ). A:int a[2][2]={{1},{2}}; B:int a[][2]={1,2,3,4}; C:int a[2][2]={{1},2,3}; D:int a[2][]={{1,2},{3,4}}; 答案:D 第3题(2.0分)题号:129 以下各标识符中,合法的用户标识符为 ( ). A:A#C B:mystery C:main D:ab* 答案:B 第4题(2.0分)题号:632 以下叙述正确的是()。 A:do-while语句构成的循环不能用其它语句构 成的循环来代替. B:do-while语句构成的循环只能用break语句 退出. C:用do-while语句构成的循环,在while后的表 达式为非零时结束循环. D:用do-while语句构成的循环,在while后的表 达式为零时结束循环 答案:D 第5题(2.0分)题号:149 以下程序的输出结果是()。 main() {float x=3.6; int i; i=(int)x; printf("x=%f,i=%d\n",x,i); } A:x=3.600000,i=4 B:x=3,i=3 C:x=3.600000,i=3 D:x=3 i=3.600000 答案:C 第6题(2.0分)题号:172 在C语言程序中()。 A:函数的定义可以嵌套,但函数的调用不可以 嵌套 B:函数的定义不可以嵌套,但函数的调用可以 嵌套 C:函数的定义和函数调用均可以嵌套 D:函数的定义和函数调用不可以嵌套 答案:B 第7题(2.0分)题号:678 当调用函数时,实参是一个数组名,则向函数 传送的是()。 A:数组的长度 B:数组的首地址 C:数组每一个元素的地址 D:数组每个元素中的值 答案:B 第8题(2.0分)题号:125 下列程序的输出结果是()。 main() {int a=7,b=5; printf("%d\n",b=b/a); } A:0 B:5 C:1 如对你有帮助,请购买下载打赏,谢谢! 一、选择题 1. 在每个C 程序中都必须包含有这样一个函数,该函数的函数名为 。 A. main B. MAIN C. name D. function 2. 在以下关于C 语言的注释的叙述中,不正确的是 。 A .注释可用"/*"、"*/"形式表示,也可用"//"形式表示 B .编译器在编译一个程序时,将跳过注释,不对其进行处理 C .编译器在编译一个程序时,可发现注释中的单词拼写错误 D .程序中注释的多少不会影响所生成的可执行文件的长度 3. 以下叙述不正确的是 。 A .在C 程序中,严格区分大小写字母 B .一个 C 源程序有且仅有一个main 函数 C .在C 程序中,注释只能位于一条语句的后面 D .一个C 程序总是从main 函数开始执行 4. 下列合法的标识符为 A. abde+ B. #KDJF C. 67KDJ D. DK3_ 5. 关于字符串和字符的关系正确的是 A. “A ”与’A ’是相同的 B. 字符串是常量,字符是变量 C. “A ”与’A ’是不同的 D. “A ”与“A ”是相同的 6. 下面关于语句的说法正确的是 A. 下面这两段程序的执行效果是一致的 B. 空语句是只有一个分号的语句,它其实什么也不干 C. 语句的构成不一定需要分号 D. 语句的书写对程序的运行不起作用,因此可以随便写都可以 7. 以下各标识符中,合法的用户标识符组为 。 A. PAd ,P#d ,b-b ,abc ,_0123,ssiped B. cin ,a10,CPP ,float ,del_word ,signed C. void ,max ,hiy , C语言模拟试题 一、判断 1、关系运算符<= =与= =的优先级相同。(N ) 2、C语言的函数可以嵌套定义。(N ) 3、若有定义和语句:int a;char c;float f;scanf(“%d,%c,%f”,&a,&c,&f);若通过键盘输入:10,A,12.5, 则a=10,c=’A’,f=12.5.( Y ) 4、变量根据其作用域的范围可以分作局部变量和全局变量。( Y ) 5、#define和printf都不是C语句。( Y ) 6、Int I,*p=&I;是正确的C说明。( Y ) 7、结构体类型只有一种。( N ) 8、在Turbo C中,整形数据在内存中占2个字节。( N ) 9、一个include命令可以指定多个被包含的文件。( N ) 10、有如下说明:int a[10]={1,2,3,4,5,6,7,8,9,10},*p=a;则数值为9的表达式是*(p+8).( Y ) 二、选择 2、C语言中,char类型数据占(A) A、1个字节 B、2个字节 C、4个字节 D、8个字节 3、已知x=43,ch=’A’,y=o;则表达式(x>=y&&ch<’B’&&!y)的值是(C) A、0 B、语法错 C、1 D、“假” 4、以下的选择中,正确的赋值语句是(C) A、a=1,b=2 B、j++ C、a=b=5 D、y=int(x) 5、C语言源程序的后缀是(B) A、exe B、c C、obj D、cp 6、执行下列语句的输出为(A) Int j=-1; if(j<=1)printf(“***\n”); Else printf(“%%%\n”); A、*** B、%%% C、%%%c D、有错,执行不正确 8、以下程序的运行结果是(A) Main() { int n; For(n=1;n<=10;n++) { if(n%3= =0) continue; Printf(“%d”,n); } } A、12457810 B、369 C、12 D、1234567890 9、以下程序段的输出结果为(B) for (i=4;i>1;i--) for(j=1;j 单选:1.以下程序的输出结果是(C) #include <> main() { int i; for(i = 1; i < 5; i++) { if(i % 2) putchar('<'); else continue; putchar('>'); } putchar ('#'); } A、< > < > < > # B、> < > < # C、< > < > # D、> < > < > < # 2. 设j和k都是int类型,则for循环语句 for(j=0,k=-1;k=1;j++,k++) printf("****\n");(B)。 A、循环体一次也不执行 B、是无限循环 C、循环结束的条件不合法 D、循环体只执行一次 3. 以下叙述正确的是(B)。 A、do-while语句构成的循环不能用其它语句构成的循环来代替. B、用do-while语句构成的循环,在while后的表达式为零时结束循环 C、用do-while语句构成的循环,在while后的表达式为非零时结束循环. D、do-while语句构成的循环只能用break语句退出. 4. 有以下程序(A) main() { int i; for(i=0; i<3; i++) switch(i) { case 1: printf("%d", i); case 2: printf("%d", i); default : printf("%d", i); } } 执行后输出结果是 A、011122 B、120 C、012020 D、012 5. 执行下面的程序段后,变量k中的值为(D) int k=3, s[2]; s[0]=k; k=s[1]*10; A、33 B、10 C、30 D、不定值 6. 以下程序中,若第一个printf语句输出的是194,则第二个printf语句的输出结果是(A) main() { int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; printf("%x\n", a); printf("%x\n", a + 9); } fgetc函数的作用是从指定文件读入一个字符,该文件的打开方式必须是()。 A、读或读写 B、追加 C、只写 D、答案B和C都正确 【参考答案】错误 A 【学生答案】 、 D 使用共用体变量,不可以()。 A、同时访问所有成员 B、进行动态管理 C、节省存储空间 D、简化程序设计 【参考答案】正确 A 【学生答案】 % A 设有如下定义:struct sk {int a; float b;} data,*p; 若要使p指向data中的a域,正确的赋值语句是()。 A、p=(struct sk*) ; B、*p=; C、p=&; D、p=&data,a; 【参考答案】错误 C \ 【学生答案】 B 以下程序段执行后输出的结果是( ). char str[ ]="ABCD",*p=str; printf("%d\n",*(p+4)); A、字符'D'的地址 B、0 C、不确定的值 D、68 【参考答案】错误 ^ B 【学生答案】 D 已定义char a[10];和char *p=a;,下面的赋值语句中正确的是( ). A、p="Turbo c"; B、a="Turbo c"; C、*p="Turbo c"; > D、a[10]="Turbo c"; 【参考答案】错误 A 【学生答案】 C 设有如下程序,请选择正确答案( )。 #include <> main() {int **k,*j,i=100; 》 j=&i, k=&j; printf("%d\n",**k); } A、运行错误 B、100 C、i的地址 D、j的地址 【参考答案】正确 B / 【学生答案】 B 以下叙述正确的是()。 A、可以把if定义为用户标识符,但不能把define定义为用户标识符 B、define和if都不能定义为用户标识符 C、可以把define定义为用户标识符,但不能把if定义为用户标识符 D、可以把define和if定义为用户标识符 【参考答案】正确 C ? 1、下面程序的输出是___D _________ #include #include 1. 编程找出4个整数中的最小值。 请打开考生文件夹下的prog1.c项目,在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。(请勿删除/**********found**********/) #include 一、单项选择题:(10分,每题2分) 1.char *p[10];该语句声明了一个:。 A)指向含有10个元素的一维字符型数组的指针变量p B)指向长度不超过10的字符串的指针变量p C)有10个元素的指针数组p,每个元素可以指向一个字符串 D) 有10个元素的指针数组p,每个元素存放一个字符串 2.若int x;且有下面的程序片断,则输出结果为:。 for (x=3; x<6; x++) { printf((x%2) ? "##%d" : "**%d\n", x); } A) ##3B) **3C) **3D)##3**4 **4 ##4 ##4**5 ##5 ##5 **5 3.在while(!x)语句中的!x与下面条件表达式等价的是:。 A) x!=0 B) x==1 C) x!=1 D) x==0 4.已知 struct point { int x; int y; }; struct rect { struct point pt1; struct point pt2; }; struct rect rt; struct rect *rp = &rt; 则下面哪一种引用是不正确的________。 A) B) (*rp). C) rp-> D)rt-> 5.若二维数组a有m行n列,则下面能够正确引用元素a[i][j]的为:。 A) *(a+j*n+i) B) *(a+i*n+j) C) *(*(a+i)+j) D) *(*a+i)+j CDDDC 二、分析程序并写出运行结果。(25分,每题5分) 1.#include <> main() {int n; static char *monthName[]= {"Illegal month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; for (n=1; n<=12; n++) { printf("%s\n", monthName[n]); } } 运行结果是: January C语言在线测试题目及 答案 SANY GROUP system office room 【SANYUA16H-SANYHUASANYUA8Q8- 第一章、第二章、第三章 第一题、单项选择题(每题1分,5道题共5分) 1、在以下关于C语言的叙述中,正确的说法是: B A、C语言比汇编语言快 B、C语言比BASIC语言快 C、C语言比BASIC语言和汇编语言都快 D、C语言比BASIC语言慢 2、在C语言中,不正确的常量是: B A、0xf6 B、0876 C、.5e-6 D、 3e 2 3、属于低级语言的计算机语言是( )。 B A、机器语言 B、汇编语言 C、Java语言 D、Pascal语言 4、对于链接,正确的说法为()。 D A、链接是将源程序和库函数链接到一起,生成可执行程序。 B、链接是将源程序、目标程序和其他源程序链接到一起,生成可执行程序。 C、链接是将源程序、库函数和其他源程序链接到一起,生成可执行程序。 D、链接是将目标程序、库函数和其他目标程序链接到一起,生成可执行程序。 5、下列不能表示常量大写英文字母A的是()。 B A、常量:‘A’ B、常量:“A” C、常量:‘\x41’ D、常量:‘\101’ 第二题、多项选择题(每题2分,5道题共10分) 1、对于16位系统中,C语言中整数 -8在内存中的错误存储形式是: BCD A、1111 1111 1111 1000 B、1000 0000 0000 0000 C、1000 0000 0000 1000 D、1111 1111 1111 0111 2、下列关于C语言用户标识符的叙述中,不正确的叙述是: ACD A、用户标识符中可以出现下划线和中划线(减号) B、用户标识符中不可以出现中划线,但可以出现下划线 C、用户标识符中可以出现下划线,但不可以放在用户标识符的开头 D、用户标识符中可以出现下划线和数字,它们都可以放在用户标识符的开头 3、关于C语言程序的语句,正确的说法是( )。 BD A、一条语句只能占一行 二,填空题(10道小题,共20分) 1、一个C源程序中至少应包含一个[main]函数。 2、a是整型变量,则执行表达式a=25/3%3后a的值为。[2] 3、int m=5,y=2;则表达式y+=y- =m*=y的值为。[-16] 4、执行下列语句: int a=1, b=2; a=a+b; b=a-b; a=a-b; printf("%d , %d \n", a,b );的输出结果分别是[2,1] 5、条件表达式的格式为表达式1?表达式2:表达式3,若表达式2和表达式3的类型不同,此时条件表达式的值的类型为二者中较[高]的类型 6、当运行以下程序时,从键盘键入right? C语言程序设计_复习题 第一部分(填空题): 1.按照C语言规定的用户标识符命名规则,不能出现在标识符中的是()。 A.大写字母 B.连接符 C.数字字符 D.下划线 答案:B 2.下面关于计算机正确的是( )。 A.计算机由硬件系统和软件系统两部分构成 B.只要有硬件系统,计算机就能工作 C.计算机只能处理文本信息 D.计算机只能处理计算问题 答案:A 3.( )是c语言提供的合法的数据类型关键字。 A.Int B.long C.Char D.integer 答案:B 4.面向过程的高级语言包括( )。 A.C,JAVA B.C,BASIC C.C++.NET,ASP D.C,VB 答案:B 5.软件按功能可以分为: 应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是( )。 A.编译程序 B. 操作系统 C.教务管理系统 D.汇编程序 答案:C 6.以下选项中关于C语言常量的叙述错误的是()。 A.所谓常量,是指在程序运行过程中,其值不能被改变的量 B.常量分为整型常量、实型常量、字符常量和字符串常量 C.常量可分为数值型常量和非数值型常量 D.经常被使用的变量可以定义成常量 答案:D 7.下面描述中正确的是()。 A.C语言提供了专门的输入/输出语句 B.C语言调用输入/输出函数时需要使用include命令包含头文件 C.C语言可以直接使用输入/输出函数 D.输入/输出函数所在的头文件是stdlib.h 答案:B 8.假设有char型变量c1,c2,执行下面程序段: c1=gatchar(); c2=gatchar(); printf(“c1=%c,c2=%c\n”,c1,c2); 如果c1和c2的值分别为字符a和b,则从键盘正确的输入方式是()。 A.ab<回车> B.a<回车>b<回车> B.C.a<空格>b<回车> D.a 江苏省计算机二级C语言试题笔试_试卷试题及答案 1.下面关于比特的叙述中,错误的是( 1 ) A.比特是组成数字信息的最小单位 B.比特只有“O”和“1”两个符号 C.比特既可以表示数值和文字,也可以表示图像和声音 D. 比特”1”总是大于比特“0” 2.在下列有关集成电路的叙述中,错误的是 ( 2 ) A.现代集成电路使用的半导体材料主要是硅 B.大觑模集成电路一般以功能部件、子系统为集成对象 C.我国第2代居民身份证中包含有IC芯片 D?目前超大规模集成电路中晶体管的基本线条已小到l 纳米左右 3.在下列有关通信技术的叙述中,错误的是 ( 3 ) A.通信的基本任务是传递信息,因而至少需由信源、信宿和信道组成 B.通信可分为模拟通信和数字通信,计算机网络属于模拟通信 C.在通信系统中,采用多路复用技术的目的主要是提高传输线路龟利用率 D学校的计算机机房一般采甩5类无屏蔽双绞线作为局域网的传输介质 4.下面是关于PC机主存储器的一些叙述,其中正确的是( 4 ) A.主存储器是一种动态随机存取存储器(RAM) B.主存储器的基本编址单位是字(即32个二进位) C.目前市场上销售的PC机,其内存容量可达数十GB D.所有PC机的内存条都是通用的:可以互换 5.现行PC机中,IDE(或SATA)接口标准主要用于 ( 5 ) A.打印机与主机的连接 c.声卡与主机的连接 B.显示器与主机的连接 D.硬盘与主机的连接 6. 下列有关PC机的CPU、内存和主板的叙述中,正确的是( 6 ) 。 A.大多数Pc机只存一块CPu芯片,即使是“双核”CPU 也是一块芯片 B.所有Pentium系列微机的内存条相同,仅有速度和容量大小之分 选择练习题 1、C 语言中最简单的数据类型包括( B )。 A 、整型,实型,逻辑型 B 、整型,实型,字符型 C 、整型,字符型,逻辑型 D 、整型,实型,逻辑型,字符型 2、C 语言中,运算对象必须是整型数的运算符是(A )。 A 、% B 、/ C 、%和/ D 、* 3、为表示关系x <y <z ,应使用C 语言表达式( A )。 A 、(x <y)&&(y <z ) B 、(x <y)AND (y <z) C 、(x <y <z) D 、(x <y) &(y <z) 4、C 语言程序的基本单位是( C )。 A 、程序行 B 、语句 C 、函数 D 、字符 5、C 语言的程序一行写不下时,可以( D )。 A 、用逗号换行 B 、用分号换行 C 、用回车符换行 D 、在任意一空格处换行 6、下述标识符中,( C )是合法的用户标识符。 A 、A&B B 、void C 、_student D 、 7、在C 语言中,字符型数据在内存中以( B A 、补码 B 、ASCII 码 C 、反码 D 、原码 8、一个程序由若干文件组成,共用同一变量,则此变量的存储类别应该为( B )。 A 、auto B 、extern C 、static D 、Register 9、以下关于switch 语句和break 语句的描述中,只有(B A 、在switch 语句中必须使用break 语句 B 、在switch 语句中,可以根据需要使用或不使用break 语句 C 、break 语句只能用于switch 语句中 D 、break 语句是switch 语句的一部分 10、C 语言规定:调用一个函数时,实参变量和形参变量之间的数据传递是(B )。 A 、地址传递 B 、值传递 C 、由实参传给形参,并由形参传回给实参 D 、由用户指定传递方式 11、下述C 语言转义符中( D )是非法的。 A 、'\b' B 、'\037' C 、'\0xf ' D 、'\'' 12、为了要计算s=10!(10的阶乘),则以下对s 的定义正确的是( D )。c语言测试题目
C语言考试试题基础版
C语言测试题
C语言考试试题
c语言考试试题
c语言期末测试题(附答案)
c语言考试试题
C语言考试试题基础版
大学C语言考试试题[1]
c语言考试题库
c语言考试题
C语言考试题库及答案精编
C语言考试题
C语言考试题及答案
C语言在线测试题目及答案
C语言考试题库之填空题
C语言考试试题
C语言考试试题及答案
C语言期末考试试题及详细答案