网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
设有如下程序段: int a[8]={0}; int b[]={0}; char c[2]={"A","B"}; char d="AB"; 以下叙述正确的是(  )。
A

只有a,b,c的定义是合法的

B

a,b,c,d的定义都是合法的

C

只有a,b的定义是合法的

D

只有c的定义是合法的


参考答案

参考解析
解析:
在对数组进行初始化时,如果对数组的全部元素赋以初值,定义时可以不指定数组长度,如果被定义数组的长度与初值个数不同,则数组长度不能省略;如果在说明数组时给出了长度,但没有给所有的元素赋予初始值,而只依次给前面的几个数组元素赋予初值,那么C语言将自动对余下的元素赋初值0。定义整型数组a,长度为8,并且其每个元素赋初值0,a定义是合法的。定义整型数组b,没有指定长度,但为1个元素赋值0,所以自动指定数组长度为1,b定义是合法的。定义字符型数组c,长度为2,应对其元素赋值字符型常量,而“A”与“B”均为字符串,c定义不合法。定义字符d,赋初值字符串“AB”,这是不合法的定义,若要定义数组,必须要有“[ ]”。可知,ab定义合法,cd定义不合法,C项正确。答案选择C选项。
更多 “单选题设有如下程序段: inta[8]={0}; intb[]={0}; charc[2]={"A","B"}; chard="AB"; 以下叙述正确的是(  )。A 只有a,b,c的定义是合法的B a,b,c,d的定义都是合法的C 只有a,b的定义是合法的D 只有c的定义是合法的” 相关考题
考题 若下面程序运行时输出结果为1, A, 10.12, B, 3.5请将程序补充完整 。#includeusing namespace std;int main(){void test(int, char,double 【 8 】 );test(1,'A',10.1);test(2,'B');return 0;}void test(int a, char b, doubleC .{cout}

考题 有如下程序: include using namespace std; int strle(char a[],char b[]) {int num= 有如下程序:include <iostream>using namespace std;int strle(char a[],char b[]){int num=O,n=O;while (* (a+num) !='\0')num++;while (b [n] ){* (a+num)=b [n];num++;n++;}return(num);}int main (){char strl[80],str2[80],*p1=str1,*p2=str2;cin>>p1;cin>>p2;cout<<strle(p1,p2)<<end1;return 0;}运行上述程序,如果从键盘输入字符串qwerty和字符串abcd,则程序的输出结果是【 】。

考题 有如下程序: include using namespace std; class Monitor{ public: Monitor(cha 有如下程序:include<iostream>using namespace std;class Monitor{public:Monitor(char t):type(t){ }void Print( )const{cout<<"The type of monitor is"<<type private:char type;};class Computer{public:Computer(int i,char C) :______{}void Print( )const{eout<<"The computer is"<<id<<endl;mort.Print( );}private:int id;Monitor mon;};int main( ){const Computer myComputer(101,'B');myComputer.Print( );return 0;}请将程序补充完整,使程序在运行时输出:The computer is 101The type of monitor is B

考题 有如下程序includevoid main(){char ch[2][5]=={"6937","8254"},*p[2];int i,j,s=0 有如下程序 #include<iostream.h> void main() {char ch[2][5]=={"6937","8254"},*p[2]; int i,j,s=0; for(i=0;i(2;i++)p[i]=ch[i]; for(i=0;i(2;i++) for(j=0;p[i][j]>'\0,j+=2) s=10*s+p[i][j]-'0'; cout<<s;} 该程序的输出结果是( )。A.69825B.63825C.6385D.693825

考题 ( 27 )有如下程序:#includeiostream#includecstringusing namespace std;class XCD{char* a;int b;public:XCD ( char* aa, int bb ) {a=new char[strlen ( aa ) +1];strcpty ( a,aa ) ;b=bb;}Char* Geta () {return a; )int Getb () { return b;}};int main () {char *pl="abcd" , *p2="weirong" ;int dl=6, d2=8;XCD x ( pl,dl ) , Y ( p2 , d2 ) ;coutstrien ( x .Geta ( ) ) +y. Getb () +endl;return 0;}运行时的输出结果是A ) 12B ) 16C ) 14D ) 11

考题 有如下程序: include using namespace std; int main() { char st 有如下程序: #include <iostream> using namespace std; int main() { char str[100], *p; cout<<"Please input a string:"; cin>>str; p=str; for (int i=0; *p!='\0'; p++,i++); cout<<i<<endl; return 0; }运行这个程序时,若输入字符串为 abcdefgabcd则输出结果是A.7B.12C.13D.100

考题 有如下程序段:int a=14,b=15,x;char c=A;x=(a&&b)&&(cB):执行该程序后,x的值为( )。A.trueB.falseC.0D.1

考题 有如下程序:includevoid main( ){char ch[2] [5] ={"6937","8254"},* p[2] ;int i, 有如下程序: #include<iostream.h> void main( ) { char ch[2] [5] ={"6937","8254"},* p[2] ; int i,j,s=0; for(i=0;i<2;i++) p[i] =ch[i] ; for(i=0;i<2;i++) for(j=0;p[i] [j] >'\0';j+=2) s=10 * s+p[i] [j] -'0'; cout < < s;} 该程序的输出结果是A.69825B.63825C.6385D.693825

考题 执行下列程序段,结果是includevoid main( ){int x=40; char y='C'; int n; n=(x0xff)(y>'B'); cout<<n;}A.0B.1C.2D.3

考题 执行下面的程序段 int x=35; char z='A'; int B; B=((x15)(z<'a')); 后,B的值为_______。A.0B.1C.2D.3

考题 有如下程序段: int a=14,b=15,x, char c='A'; x=(aB) (c<'B'); 执行该程序段后,x的值为( )A.1B.0C.FALSED.TRUE

考题 执行下列程序段,结果是includevoid main( ){int x=40; char y='C'; int n;?n=(x char y='C'; int n; ? n=(x0) xff) (y>'B') ; cout < < n;}A.0B.1C.2D.3

考题 有如下程序段#include "stdio.h"#include "string.h"#define N 10#define M 10char *find(char(*a)[M],int n){ char *q;int i; q=a[0]; for(i=0;in;i++) if(strcmp(a[i],q)0)q=a[i]; return q;}main(){ char s[N][M]={"tomeetme","you","and","he","china"}; char *p; int n=5; p=find(s,n); puts(p);}则执行后输出的结果为A.he B.and C.you D.tomeetme

考题 有如下程序includevoid main( ){char ch[2][5]={"6937","8254"},*p[2];int i,j,s=0 有如下程序 #include<iostream.h> void main( ) { char ch[2][5]={"6937","8254"},*p[2]; int i,j,s=0; for(i=0;i<2;i++)p[i]=ch[i]; for(i=0;i<2;i++) for(j=0;p[i][j]>'\0';j+=2) s=10*s+p[i][j]-'0';A.69825B.63825C.6385D.693825

考题 有一段C程序如下,执行后,其运行结果为(52)。 int f(int a){ auto int b = 0; static int c = 3; b ++; c++; return(a+b+c); } main(){ int a=2,i; for(i=0; i<3; i++)printf("%d, ",f(a)); }A.7,8,9,B.7,7,7,C.6,7,8,D.9,8,7,

考题 有如下程序段void func(int *a,int b[ ]){ b[0]=*a+6; }main(){ int a,b[5]={0}; a=0;b[0]=3; func(a,b); printf("%d\n",b[0]); }程序运行后输出的结果是A.6 B.7 C.8 D.9

考题 若有如下程序段: include using namespace std; int main() {char*p="abcdefgh",*r;l 若有如下程序段:include <iostream>using namespace std;int main(){char *p="abcdefgh",*r;long *q;q=(long *)p;q++;r=(char *)q;cout<<r<<end1;return 0;}该程序的输出结果是______。

考题 执行下面的程序段 int x=40; char z='B'; int B; B=((x0xff)(z>'a')); 后,B的值为( )A.0B.1C.2D.3

考题 有如下程序段: int a=14,b=15,x; char c='A'; x=(ab)(c<'B'); 执行该程序段后,x的值为( )。A.tureB.假C.0D.1

考题 有如下程序includevoid main(){char ch[2][5]={"6937","8254"},*p[2];int i,j,s=0; 有如下程序 #include<iostream.h> void main() {char ch[2][5]={"6937","8254"},*p[2]; int i,j,s=0; for(i=0;i<2;i++)p[i]=ch[i]; for(i=0;i<2;i++) for(j=0;p[i][j]>'\0';j+=2) s=10*s+p[i][j]-'0'; cout<<s; return 0; } 该程序的输出结果是( )。A.69825B.63825C.6385D.693825

考题 有如下程序段includevoid main(){int a=14,b=15,x;char c='A':x=(a 有如下程序段 include<iostream.h> void main() {int a=14,b=15,x; char c='A': x=(a b) (c<'B'=; cout<<x;= 执行该程序段后,x的值为A.tureB.FALSEC.0D.1

考题 有如下程序段int a=14,b=15,x;char c=′A′;x=(ab)(c′B′);执行该程序段后,x的值为A.trueB.falseC.0D.1

考题 有如下程序:includeusing namespace std;class Toy{public:Toy(char*_n){strcpy(name 有如下程序: #include<iostream> using namespace std; class Toy{ public: Toy(char*_n){strcpy(name,_n);count++;} ~Toy(){count--;} char*GetName( ){return name;} static int getCount( ){return count;} private: char name[10]; static int count; }; int Toy::count=0: int main( ){ Toy tl("Snoopy"),t2("Mickey"),t3("Barbie"); cout<<t1.getCount( )<<endl; return 0; } 程序的输出结果是A.1B.2C.3D.运行时出错

考题 如下程序的输出结果是includeincludeusing namespace std;class XCD{char* 如下程序的输出结果是 #include<lostream> #include<cstring> using namespace std; class XCD{ char*a; int b; public: XCD(char*aa,int bB) { a=new char[strlen(aA) +1]; strcpy(a,aA) ; b=bb; } char*Geta( ){return a;} int Getb( ){return b;} }; int main( ){ char*pl="abcd",*p2="weirong": int dl,6,d2=8; XCD x(pl,d1),y(p2,d2); cout<<strlen(x.Geta( ))+y.Getb( )<<endl; return 0; }A.12B.16C.14D.11

考题 有下列程序段:include using namespace std;int main() { char b[]= "Hello,you"; b[ 有下列程序段: #include <iostream> using namespace std; int main() { char b[] = "Hello,you"; b[5] = 0; cout<<b<<end1; return 0; } 执行此程序后,得到的输出结果是( )。A.Hello,youB.Hello0youC.HelloD.0

考题 有如下程序段includevoid main(){int a=14,b=15,x;char c='A'x=(ab) 有如下程序段 include<iostream.h> void main() {int a=14,b=15,x; char c='A' x=(ab)(c<'B'=; cout<<x;= 执行该程序段后,x的值为A.tureB.假C.0D.1

考题 执行下列程序段,结果是 #include(iostream.h> void main() { int x=40; char y=‘C’;int n; n=(x0xff)(y>‘B’); cout<<n;}A.0B.1C.2D.3

考题 设有如下程序,其调试结果为:class Q2 {public static void main(String[] args) {int[] seeds = {1,2,3,4,6,8};int n= seeds.length;for (int i = 0; ifor (int k = 0; kseeds[k]= seeds[k+1];for (int i = 0; iSystem.out.print("/t"+seeds[i]);}}A.输出: 1 2 3 4 6B.输出: 4 6 8 8 8C.输出: 2 3 4 6 8D.输出: 2 3 4 6