0
点赞
收藏
分享

微信扫一扫

C语言练习题组01

witmy 2022-01-13 阅读 84
1. 设有定义语句:char c1 = 92, c2 = 92;,则以下表达式中值为零的是()
  • c1^c2
  • c1&c2
  • ~c2
  • c1|c2
2. 下列程序输出什么
#include<stdio.h>
#include<string.h>

int main() {
    int n;
    char y[10] = "ntse";
    char *x = y;
    n = strlen(x);
    *x = x[n];
    x++;
    printf("x=%s,", x);
    printf("y=%s\n", y);
    return 0;
}
  • x=atse,y=
  • x=tse,y=
  • x=atse,y=e
  • x=tse,y=e
3. 给定下面函数:整数单链表作为参数,函数重新排列列表的元素。
现以顺序为 1, 2, 3, 4, 5, 6, 7 的整数列表调用该函数
struct node
{
    int value;
    struct node *next;
};
 
void rearrange(struct node *list)
{
   struct node *p, * q;
   int temp;
   if ((!list) || !list -> next)
      return;
   p = list;
   q = list -> next;
   while(q)
   {
       temp = p -> value;
       p -> value = q -> value;
       q -> value = temp;
       p = q -> next;
       q = p ? p -> next:0;
   }
} 
  • 1, 2, 3, 4, 5, 6, 7
  • 2, 1, 4, 3, 6, 5, 7
  • 1, 3, 2, 5, 4, 7, 6
  • 2, 3, 4, 5, 6, 7, 1
4. 数组a的定义为:int a[3][4]; 下面哪个不能表示 a[1][1] ?
  • *(&a[0][0]+5)
  • ((a+1)+1)
  • *(&a[1]+1)
  • *(a[1]+1)
5. 下面程序的输出结果是
#include <iostream>
using namespace std;

int main() 
{
    char str1[] = "hello world";  
    char str2[] = "hello world";  

    const char str3[] = "hello world";  
    const char str4[] = "hello world";  

    const char* pstring1 = "hello world";  
    const char* pstring2 = "hello world";  

    cout << boolalpha << ( str1==str2 ) <<  ',' ; 
    cout << boolalpha << ( str3==str4 ) << ',' ;  
    cout << boolalpha << ( pstring1==pstring2 ) <<endl;

    return 0;
}
  • false,false,true
  • false,false,false
  • true,true,true
  • false,true,true
6. 下面选项中的程序段,没有编译错误的是()
  • char* sp, s[10]; sp = “Hello”;
  • char* sp, s[10]; s = “Hello”;
  • char str1[10] = “computer”, str2[10]; str2 = str1;
  • char mark[]; mark = “PROGRAM”;
7. 有下面C++代码
struct A{
  void foo(){printf("foo");}
  virtual void bar(){printf("bar");}
  A(){bar();}
};
struct B:A{
  void foo(){printf("b_foo");}
  void bar(){printf("b_bar");}
};
那么下列代码输出为
A *p = new B;
p->foo();
p->bar();
  • barfoob_bar
  • foobarb_bar
  • barfoob_foo
  • foobarb_fpp
8. 下列main函数的输出结果是

在这里插入图片描述

  • 17
  • 15
  • 16
  • 1
9. 若有以下说明和定义,在必要的赋值之后,对fun函数的正确调用语句是()
int fun (int *c)  {}
void main(){
    int (*a)(int*)=fun,*b(),w[10],c;
	// ... ...
}
  • a=a(w);
  • (*a)(&c);
  • b=*b(w);
  • fun(b);
10. 看下面的代码
unsigned int a = 0x1234;
unsigned char b = *(unsigned char *)&a; 
在 32 位大端模式处理器上变量 b 等于()
  • 0x00
  • 0x12
  • 0x34
  • 0x1234



练习答案

举报

相关推荐

0 条评论