I come, I see, I conquer

                    —Gaius Julius Caesar

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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 <stdio.h>

struct student
{
    int no;
    char name[20];
};

void main()
{
    student s;
    s.name = "hello";
    printf("hello");
}
#include <stdio.h>

struct student
{
    int no;
    char name[20];
};

void main()
{
    student s;
    printf("%s", s.name);
}
#include <stdio.h>

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

 

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

#include <stdio.h>

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 <stdio.h>

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 <stdio.h>

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 <stdio.h>

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) #x

int main()
{ 
    printf("%s", call(c/c++));
}
int main()
{ 
    if(printf("aaaaaaaa"))
        printf("yes"); 
    else 
        printf("no");
}

 

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

#include <stdio.h>

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 <stdio.h>

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 <stdio.h>

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 <stdio.h>

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 <iostream>

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、以下代码的输出结果是多少?

 

posted on 2014-03-06 17:44  jcsu  阅读(794)  评论(0编辑  收藏  举报