I come, I see, I conquer

                    —Gaius Julius Caesar

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

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

#include <stdio.h>

void main()
{
    int a[5] = {1, 2, 3, 4, 5};
    int i;
    for (i = 0; i < 5; i++)
        if ((char)a[i] == '5')
            printf("%d\n", a[i]);
        else
            printf("FAIL\n");
}

 

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

#include <stdio.h>

void main()
{
    char s[] = "abc";
    int i;
    for(i=0; s[i]; i++)
        printf("%c%c%c%c", s[i], *(s+i), *(i+s), i[s]);
}

 

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

#include  <stdio.h>

int main()
{
    char c;
    FILE *file;
    file = fopen("test.txt", "w+");
    fprintf(file, "%c", 'a');
    fprintf(file, "%c", -1);
    fprintf(file, "%c", 'b');
    fclose(file);
    file = fopen("test.txt", "r");
    while ((c = fgetc(file)) != -1)
        printf("%c", c);
    return 0;
}

 

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

int main()
{
    int x = 0;
    if (x = 0)
        printf("Its zero\n");
    else
        printf("Its not zero\n");
}

 

5、以下程序的输出结果是多少?

#include <stdio.h>

void main()
{
    int k = 8;
    int x = 0 == 1 && k++;
    printf("%d%d\n", x, k);
}

 

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

#include <stdio.h>

void main()
{
    char a = 'a';
    int x = (a % 10)++;
    printf("%d\n", x);
}

 

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

void main()
{
    unsigned int x = -5;
    printf("%d", x);
}

 

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

void main()
{
    char *p = 0;
    *p = 'a';
    printf("value in pointer p is %c\n", *p);
}
void main()
{
    if (sizeof(int) > -1)
        printf("True");
    else
        printf("False");
}
void main()
{
     char *p = "Sanfoundry C-Test";
     p[0] = 'a';
     p[1] = 'b';
     printf("%s", p);
}

 

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

void main()
{
     int n = 0, m = 0;
     if (n > 0)
         if (m > 0)
             printf("True");
     else 
         printf("False");
}

 

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

void main()
{
     float f1 = 0.1;
     if (f1 == 0.1)
         printf("equal\n");
     else
         printf("not equal\n");
}
void main()
{
     float f1 = 0.1;
     if (f1 == 0.1f)
         printf("equal\n");
     else
         printf("not equal\n");
}
void main()
{
     float x = 'a';
     printf("%f", x);
}

 

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

void main()
{
    enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
    printf("PEACH = %d\n", PEACH);
}
void main()
{
    printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
}
void main()
{
    char *str = "abc.com.cn\0" "last string";
    printf("%s", str);
}
#define a 20

void main()
{
    const int a = 10;
    printf("a = %d\n", a);
}
void main()
{
    int var1 = 010;
    int var2 = 0x10;
    printf("%d, %d", var1, var2);
}
enum birds {SPARROW, PEACOCK, PARROT};
enum animals {TIGER = 8, LION, RABBIT, ZEBRA};

void main()
{
     enum birds m = TIGER;
     int k;
     k = m;
     printf("%d\n", k);
}
#define MAX 2
enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};

void main()
{
     enum bird b = PARROT;
     printf("%d\n", b);
}

 

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

void main()
{
     char *str = "x";
     char c = 'x';
     char ary[1];
     ary[0] = c;
     printf("%d %d", strlen(str), strlen(ary));
}
void main()
{    
    printf("sanfoundry\rclass\n");
}
void main()
{    
    printf("sanfoundry\r\nclass\n");
}

 

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

void main()
{    
    const int p;
    p = 4;
    printf("p is %d", p);
}
void main()
{    
    int k = 4;
    int *const p = &k;
    int r = 3;
    p = &r;
    printf("%d", p);
}
void main()
{
    int const k = 5;
    k++;
    printf("k is %d", k);
}

 

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

void foo(const int *);
int main()
{
    const int i = 10;
    printf("%d ", i);
    foo(&i);
    printf("%d", i); 
}
void foo(const int *i)
{
    *i = 20;
}
int main()
{
    const int i = 10;
    int *ptr = &i;
    *ptr = 20;
    printf("%d\n", i);
}

 

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

int main()
{
    int i = -3;
    int k = i % 2;
    printf("%d\n", k);
}
int main()
{
     int i = 3;
     int l = i / -2;
     int k = i % -2;
     printf("%d %d\n", l, k);
}
int main()
{
     int x = 5.3 % 2;
     printf("value of x is %d", x);
}
int main()
{
     int a = 3;
     int b = ++a+a+++--a;
     printf("Value of b is %d", b);
}
int main()
{
    int a = 10;
    double b = 5.6;
    int c;
    c = a + b;
    printf("%d", c);
}

 

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

int main()
{
    int x = 1, y = 0, z = 5;
    int a = x && y || z++;
    printf("%d", z);
}
int main()
{
    int x = 1, y = 1, z = 5;
    int a = x && y || z++;
    printf("%d", z);
}
int main()
{
    int x = 1, y = 0, z = 5;
    int a = x && y && z++;
    printf("%d", z);
}
int main()
{
    int x = 1, y = 0, z = 3;
    x > y ? printf("%d", z) : return z;
}
int main() 
{
    int i = 1;
    if (i++ && (i == 1))
        printf("Yes\n");
    else
        printf("No\n");
}
int main()
{
    int a = 10, b = 5, c = 3;
    b != !a;
    c = !!a;
    printf("%d\t%d", b, c);
}
int main() //赋值和单目运算符的结合顺序是从右往左结合,其他是从左往右结合
{
    int a = 10;
    if (a == a--)
        printf("TRUE 1\t");
    a = 10;
    if (a == --a)
        printf("TRUE 2\t");
}

 

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

int main()
{
    double x = 123828749.66;
    int y = x;
    printf("%d\n", y);
    printf("%lf\n", y);
}
int main() //带符号型向无符号型转换?
{
     unsigned int i = 23;
     signed char c = -23;
     if (i > c)
         printf("Yes\n");
     else if (i < c)
         printf("No\n");
}
int main()
{
     int i = 23;
     char c = -23;
     if (i > c)
         printf("Yes\n");
     else if (i < c)
         printf("No\n");
}
int main()
{
     short int i = 20;
     char c = 97;
     printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
}

 

posted on 2014-03-05 17:08  jcsu  阅读(1107)  评论(0编辑  收藏  举报