跪求C语言大神解决这些C语言选择题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跪求C语言大神解决这些C语言选择题相关的知识,希望对你有一定的参考价值。
下列描述中正确的是:
A. 程序就是软件
B. 软件开发不受计算机系统的限制
C. 软件既是逻辑实体,又是物理实体
D. 软件是程序、数据与相关文档的集合
以下不能定义为用户标识符是:
A. a
B. _0
C. _int
D. sizeof
在C语言中,假定有以下变量定义:
int k=7 ,x=12;
则能使其值为 3 的表达式是:
A. x%=(k%=5)
B. x%=(k-k%5)
C. x%=k-k%5
D. (x%=k)-(k%=5)
在C语言中,设x,y,z,t均为int型变量,则执行以下语句后,t的值为:
x=y=z=1;
t=++x||++y&&++z
A. 不定值
B. 2
C. 1
D. 0
在C语言中,能正确表示a≥10或a≤0的关系表达式是:
A. a>=10 or a<=0
B. a>=10│a<=0
C. a>=10 && a<=0
D. a>=10 || a<=0
在C语言中,若w=1, x=2 , y=3, z=4; 则条件表达式: w>x?w:y<z?y:z的结果为:
A. 4
B. 3
C. 2
D. 1
在C语言中,执行下面两个语句后,输出的结果为:
char c1=97, c2=98;
printf("%d %c",c1,c2);
A. 97 98
B. 97 b
C. a 98
D. a b
执行了以下程序段后,正确的a,b,c值应为:
int a=7,b=8,c=9;
if(a>b)
a=b;b=c;c=a;
A. a=7 b=8 c=7
B. a=7 b=9 c=7
C. a=8 b=9 c=7
在C语言中,设已定义k为int整型变量,则下面while循环的执行次数为:
k=10;
while(k=0) k=k-1;
A. 执行10次
B. 无限循环
C. 一次也不执行
D. 执行一次
有以下程序段:
for(a=1,b=1;b<=10;b++)
if(a>=8)break;
printf("%d\n",b);
则b的值是:
A. 3
B. 4
C. 10
语言中while与do-while语句的主要区别是:
A. do-while的循环体至少无条件执行一次
B. do-while允许从外部跳到循环体内
C. while的循环体至少无条件执行一次
D. while的循环控制条件比do-while的严格
下列程序段执行结果是:
int x=2;
do
printf("%2d",x--);
while(!x);
A. 2 1
B. 2
C. 1
如下循环语句的执行次数为:
for(i=0,j=2;j=1;i++,j--)
A. 循环体执行2次
B. 循环条件不合法
C. 循环体只执行1次
D. 是无限循环
在C语言中,若有定义:static int x[2][3]=2,3,4,5,6,7,则表达式*&x[1]
值为:
A. 2
B. 3
C. 4
D. 5
下面叙述中,不正确的是:
A. 函数的定义不能嵌套,但函数调用可以嵌套
B. 为了提高可读性,编写程序时应该适当使用注释
C. 变量定义时若省去了存储类型,系统将默认其为静态型变量
D. 函数中定义的局部变量的作用域在函数内部
以下语句的输出结果为:
int k=017;
printf("%d\n",k);
A. 15
B. 16
C. 17
D. 0
以下程序段运行后的输出结果是:
#define N 20
int i,a[N]=1,2,3,4,5,6,7,8,9,10;
for(i=0;i<5;i++)printf("%d",a[i]);
A. 10234
B. 12344
C. 12334
D. 12234
D
D
D
C
D
B
B
B
C
无正确选项,应该是b=11
A
A
D
D
C
A
无正确选项,应该是12345
D
B
C
C
B
B
B
C
C
A
B
B
D
C
D
12345
本人碰见一道C语言难题,寻大神帮助,利用C语言实现:求任意两个集合的交集、并集、差集,
以前写过一个纯C的, 用的是数组,模拟C++ STL里面的set_intersection,set_union和set_difference的实现。 稍作了修改,添加了些注释,希望能帮到你。注意:必须先对输入集合排序;输出结果和C++ STL的测试结果吻合。
#include <stdio.h>#include <stdlib.h>
#include <string.h>
int set_intersection (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes);
int set_union (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes);
int set_difference (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes);
int compare (const void * a, const void * b);
void print_array(const int arr[], const size_t len);
int main(int argc, char** argv)
int first[] = 5,10,15,20,25;
int second[] = 50,40,30,20,10;
unsigned int size1, size2, size_intxn, size_union, size_diff, retcode;
int *pr_intxn, *pr_union, *pr_diff;
/* Pre-requirement, set MUST be sorted. */
size1 = sizeof(first) / sizeof(first[0]);
size2 = sizeof(second) / sizeof(second[0]);
qsort(first, size1, sizeof(int), compare);
qsort(second, size2, sizeof(int), compare);
/* Intersection */
size_intxn = (size1 > size2) ? size1 : size2; /* estimate size of result */
pr_intxn = (int *)malloc(sizeof(int) * size_intxn); /* pre-allocate result */
if (NULL == pr_intxn)
printf("Intersection memory error.\\n");
return -1;
printf("1) Set of Intersection:\\n");
retcode = set_intersection(first, size1, second, size2, pr_intxn, &size_intxn);
if (retcode == 0)
print_array(pr_intxn, size_intxn);
else
printf("Error in set_intersection, code %d\\n", retcode);
free(pr_intxn);
/* Union */
size_union = size1 + size2; /* estimate size of result */
pr_union = (int *)malloc(sizeof(int) * size_union); /* pre-allocate result */
if (NULL == pr_union)
printf("Union memory error.\\n");
return -1;
printf("2) Set of Union:\\n");
retcode = set_union(first, size1, second, size2, pr_union, &size_union);
if (retcode == 0)
print_array(pr_union, size_union);
else
printf("Error in set_union, code %d\\n", retcode);
free(pr_union);
/* Difference */
size_diff = size1 + size2; /* estimate size of result */
pr_diff = (int *)malloc(sizeof(int) * size_diff); /* pre-allocate result */
if (NULL == pr_diff)
printf("Difference memory error.\\n");
return -1;
printf("3) Set of Difference:\\n");
retcode = set_difference(first, size1, second, size2, pr_diff, &size_diff);
if (retcode == 0)
print_array(pr_diff, size_diff);
else
printf("Error in set_difference, code %d\\n", retcode);
free(pr_diff);
return 0;
/*
Input:
Set1 - First set.
Set2 - Second set.
SizeofSet1 - Set length of First set.
SizeofSet2 - Set length of Second set.
Input/Output:
Res - Set for storing results.
pSizeofRes - Point to SizeofRes, length of result. If SizeofRes is less than
expected, a proper size will be returned to caller.
Return:
0 - If successfully.
1 - SizeofRes is smaller than expected.
-1 - Internal memory error.
*/
int set_difference (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes)
int i, j, k;
unsigned int size_pre;
int *pr = 0;
size_pre = SizeofSet1 + SizeofSet2;
if ( *pSizeofRes < size_pre)
*pSizeofRes = size_pre;
return 1;
pr = (int *)malloc(size_pre * sizeof(int));
if ( pr == NULL )
return -1;
i = 0; j = 0; k = 0;
while ( i < SizeofSet1 && j < SizeofSet2 )
if (Set1[i] < Set2[j]) pr[k++] = Set1[i++];
else if (Set2[j] < Set1[i]) ++j;
else
i++; j++;
memcpy(pr+k, Set1+i-1, sizeof(int)*(SizeofSet1-i+1));
k += SizeofSet1-i;
memcpy(Res, pr, k*sizeof(int));
*pSizeofRes = k;
free(pr);
return 0;
int set_union (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes)
int i, j, k;
unsigned int size_pre;
int *pr = 0;
size_pre = SizeofSet1 + SizeofSet2;
if ( *pSizeofRes < size_pre)
*pSizeofRes = size_pre;
return 1;
pr = (int *)malloc(size_pre * sizeof(int));
if ( pr == NULL )
return -1;
i = 0; j = 0; k = 0;
while ( 1 )
if (i > SizeofSet1 - 1)
memcpy(pr+k, Set2+j-1, sizeof(int)*(SizeofSet2-j+1));
k += SizeofSet2 - j;
break;
if (j > SizeofSet2 - 1)
memcpy(pr+k, Set1+i-1, sizeof(int)*(SizeofSet1-i+1));
k += SizeofSet1 - i;
break;
if (Set1[i] < Set2[j]) pr[k] = Set1[i++];
else if (Set2[j] < Set1[i]) pr[k] = Set2[j++];
else pr[k] = Set1[i]; ++i; ++j;
++k;
memcpy(Res, pr, k*sizeof(int));
*pSizeofRes = k;
free(pr);
return 0;
int set_intersection (const int Set1[], const unsigned int SizeofSet1,
const int Set2[], const unsigned int SizeofSet2,
int Res[], unsigned int* pSizeofRes)
int i, j, k;
unsigned int size_pre;
int *pr = 0;
size_pre = (SizeofSet1 > SizeofSet2) ? SizeofSet1 : SizeofSet2;
if ( *pSizeofRes < size_pre)
*pSizeofRes = size_pre;
return 1;
pr = (int *)malloc(size_pre * sizeof(int));
if ( pr == NULL )
return -1;
i = 0; j = 0; k = 0;
while ( i < SizeofSet1 && j < SizeofSet2 )
if (Set1[i] < Set2[j]) ++i;
else if (Set2[j] < Set1[i]) ++j;
else
pr[k++] = Set1[i];
i++; j++;
memcpy(Res, pr, k*sizeof(int));
*pSizeofRes = k;
free(pr);
return 0;
void print_array(const int arr[], const size_t len)
int i;
for (i = 0; i < len; i++)
printf("%d ", arr[i]);
printf("\\n");
int compare (const void * a, const void * b)
return ( *(int*)a - *(int*)b );
参考技术A 具体忘了,利用链表可以求解,参考严蔚敏 数据结构(C语言版)
以上是关于跪求C语言大神解决这些C语言选择题的主要内容,如果未能解决你的问题,请参考以下文章
用C语言数据结构编写 删除顺序表中值为x的元素 跪求大神解答 ! !