博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c、c++ 基础试题(3)
阅读量:6259 次
发布时间:2019-06-22

本文共 5575 字,大约阅读时间需要 18 分钟。

1、以下代码的输出结果是多少?

int main(){    int i = 1;    i = ++i + ++i + ++i;    printf("%d\n", i);    printf("%d %d %d",i,++i,i++);}
int main(){     int a = 1, b = 1, c;     c = a+++b;     printf("%d, %d, %d", a, b, c);}
int main(){      int a = 1, b = 1, d = 1;      printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);}
int main(){    int i = 0;    int x = i++, y = ++i;    printf("%d % d\n", x, y);}

 

2、以下代码的输出结果是多少?

int main() //{    int x = 4;    int *p = &x;    int *k = p++;    int r = p - k;    printf("%d", r);}

 

3、以下代码的输出结果是多少?

int main(){    int a = 5, b = -7, c = 0, d;    d = ++a && ++b || ++c;    printf("\n%d%d%d%d", a,  b, c, d);}

 

4、以下代码的输出结果是多少?

int main(){    char a[10][5];    printf("%p\n", a);    printf("%p\n", a[0]);    printf("%d", sizeof(a[1]));}

 

5、以下代码的输出结果是多少?

int main(){    char *a[1] = {
"hello"}; printf("%s", a[0]);}

 

6、以下代码的输出结果是多少?

int main(){    char *a[2] = {
"hello", "hi"}; printf("%d", sizeof(a));}
int main(){    char a[2][6] = {
"hello", "hi"}; printf("%d", sizeof(a));}
int main() //{    char a[2][6] = {
"hello", "hi"}; printf("%s", *a + 1);}
int main(){    char *a[2] = {
"hello", "hi"}; printf("%s", *(a + 1));}

 

7、以下代码的输出结果是多少?

#include 
struct student{ int no; char name[20];};void main(){ student s; s.name = "hello"; printf("hello");}
#include 
struct student{ int no; char name[20];};void main(){ student s; printf("%s", s.name);}
#include 
struct student{ int no; char name[20];};struct student s;void main(){ s.no = 10; printf("%s", s.name);}

 

8、以下代码的输出结果是多少?

#include 
void (*(f)())(int, float);void (*(*x)())(int, float) = f;void ((*y)(int, float));void foo(int i, float f);int main(){ y = x(); y(1, 2);}void (*(f)())(int, float){ return foo;}void foo(int i, float f){ printf("%d %f\n", i, f);}

 

9、以下代码的输出结果是多少?

#include 
void (*(f)())(int, float);typedef void (*(*x)())(int, float);void foo(int i, float f);int main(){ x = f; x();}void (*(f)())(int, float){ return foo;}void foo(int i, float f){ printf("%d %f\n", i, f);}

 

10、以下代码的输出结果是多少?

#include 
void (*(f)())(int, float);typedef void (*(*x)())(int, float);void foo(int i, float f);int main(){ x p = f; p();}void (*(f)())(int, float){ return foo;}void foo(int i, float f){ printf("%d %f\n", i, f);}

 

11、以下代码的运行结果是多少?

struct S {    int i;    int * p;};void main(){    S s;    int * p = &s.i;    p[0] = 4;    p[1] = 3;    s.p = p;    s.p[1] = 1;    s.p[0] = 2;}

 

12、以下代码的输出结果是多少?

#include 
struct marks { int p:3; int c:3; int m:2;}; int main(){ struct marks s = {
2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); return 0; }

 

13、以下代码的输出结果是多少?

int main(){    int i;     float a = 5.2;    char *ptr;     ptr = (char *)&a;     for(i = 0; i <= 3; i++)         printf("%d ",*ptr++); }
int main(){    int i;     double a = 5.2;    char *ptr;     ptr = (char *)&a;     for(i = 0; i <= 7; i++)         printf("%d ",*ptr++); }

 

14、以下代码的输出结果是多少?

int main(){    printf("%s", "c" "question" "bank");}
int main(){    char *str = "c-pointer";     printf("%*.*s", 10, 7, str);}
int main(){    int a = -12;     a = a >> 3;     printf("%d",a);}

 

15、以下代码的输出结果是多少?

int extern x; int main() {    printf("%d", x);    x = 2;} int x=23;

 

16、以下代码的输出结果是多少?

#define message "union is \  power of c" int main(){     printf("%s",message); }
#define call(x) #xint main(){     printf("%s", call(c/c++));}
int main(){     if(printf("aaaaaaaa"))        printf("yes");     else         printf("no");}

 

17、以下代码的输出结果是多少?

#include 
struct s1{ int a : 1; int b : 1;};struct s2{ int a : 20; int b : 12;};struct s3{ int a : 20; int b : 13;};/*************/struct x1{ char a : 1; int b : 1;};struct x2{ char a : 1; int b : 8;};struct x3{ char a : 8; int b : 32;};int main(){ printf("%d, %d, %d\n", sizeof(struct s1), sizeof(struct s2), sizeof(struct s3)); printf("%d, %d, %d\n", sizeof(struct x1), sizeof(struct x2), sizeof(struct x3)); }

 

18、以下代码的输出结果是多少?

#include 
union u{ struct p { unsigned char x : 2; unsigned int y : 2; }; int x;}; int main(){ union u u; u.p.x = 2; printf("%d\n", u.p.x);}
#include 
union u{ struct { unsigned char x : 2; unsigned int y : 2; }p; int x;}; int main(){ union u u; u.p.x = 2; printf("%d\n", u.p.x);}
#include 
union u{ struct { unsigned char x : 2; unsigned int y : 2; }p; int x;}; int main(){ union u u.p.x = 2; printf("%d\n", u.p.x);}

 

19、以下代码的输出结果是多少?

union u{    struct    {        unsigned char x : 2;        unsigned int y : 2;    }p;    int x;};    int main(){    union u u = {
2}; printf("%d\n", u.p.x);}

 

20、以下代码的输出结果是多少?

struct p //{    unsigned int x : 2;    unsigned int y : 2;};    int main(){    struct p p;    p.x = 3;    p.y = 4;    printf("%d,%d\n", p.x, p.y);}
struct p{    unsigned int x : 7;    unsigned int y : 2;};    int main(){    struct p p;    p.x = 110;    p.y = 2;    printf("%d\n", p.x);}

 

21、指出下列程序在哪一行崩溃?

#include 
struct MyStruct{ char c; char *p;};using namespace std;int main(){ struct MyStruct s; char *p=&s.c; p[0] = 0; p[1] = 1; p[2] = 2; p[3] = 3; p[4] = 4; p[5] = 5; s.p=p; s.p[0] = 5; s.p[1] = 4; s.p[2] = 3; s.p[3] = 2; s.p[4] = 1; s.p[5] = 0; for(int i = 0;i<5;i++) cout << p[i] << " "; return 1;}

 

22、以下代码的输出结果是多少?

 

转载地址:http://wcqsa.baihongyu.com/

你可能感兴趣的文章
php断点续传之分割合并文件
查看>>
Lesson 5-Exchange server 2010 Transfer mails in public network
查看>>
Chrome源码剖析【三】
查看>>
windows系统自带命令查看硬件信息,怎样dos命令查看硬盘和内存/CPU信息
查看>>
Nginx基础应用--------基于CentOS6源码安装
查看>>
流媒体服务器之nginx的rtmp模块
查看>>
AChartEngine中属性XYMultipleSeriesRenderer和XYSeriesRender属性详解
查看>>
免费的上网行为管理系统和软路由系统推荐。
查看>>
dovecot+mysql
查看>>
c#短信接口代码实现(发短信)
查看>>
nginx hello world模块编译运行的问题
查看>>
磁盘空间满引起的mysql启动失败:ERROR! MySQL server PID file could not be found!
查看>>
对症下药 避免显示器偏离色彩“正轨”
查看>>
MySQL权限经验原则
查看>>
apache下实现301永久性重定向的方法
查看>>
fir.im 持续集成技术实践
查看>>
windows快捷键使用
查看>>
Java 字符串处理
查看>>
安装nginx服务实战
查看>>
Python基础语法
查看>>