几个C语言的题目# JobHunting - 待字闺中
b*7
1 楼
1. what's the output? why?
#include
#include
int main()
{
while(1)
{
fprintf(stdout,"hello-std-out");
fprintf(stderr,"hello-std-err");
sleep(1);
}
return 0;
}
2. what's the output?
#include
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", (int)a);
printf("%d\n", *(int *)&a);
return 0;
}
3. can it be built? if yes, what's the result?
file1.c:
int arr[80];
file2.c:
extern int *arr;
int main()
{
arr[1] = 100;
printf("%d\n", arr[1]);
return 0;
}
4. what's the output?
#include
int main()
{
int i;
i = 10;
printf("i : %d\n",i);
printf("sizeof(i++) is: %d\n",sizeof(i++));
printf("i : %d\n",i);
return 0;
}
5. what's the output?
#include
int main()
{
char dummy[80];
printf("Enter a string:\n");
scanf("%[^r]",dummy);
printf("%s\n",dummy);
return 0;
}
6. which are valid?
int (*pf)(void);
int f(void)
{
pf = &f;
pf = ***f;
pf();
(****pf)();
(***************f)();
}
7. what does it return?
return ((1 - sizeof(int)) >> 32);
#include
#include
int main()
{
while(1)
{
fprintf(stdout,"hello-std-out");
fprintf(stderr,"hello-std-err");
sleep(1);
}
return 0;
}
2. what's the output?
#include
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", (int)a);
printf("%d\n", *(int *)&a);
return 0;
}
3. can it be built? if yes, what's the result?
file1.c:
int arr[80];
file2.c:
extern int *arr;
int main()
{
arr[1] = 100;
printf("%d\n", arr[1]);
return 0;
}
4. what's the output?
#include
int main()
{
int i;
i = 10;
printf("i : %d\n",i);
printf("sizeof(i++) is: %d\n",sizeof(i++));
printf("i : %d\n",i);
return 0;
}
5. what's the output?
#include
int main()
{
char dummy[80];
printf("Enter a string:\n");
scanf("%[^r]",dummy);
printf("%s\n",dummy);
return 0;
}
6. which are valid?
int (*pf)(void);
int f(void)
{
pf = &f;
pf = ***f;
pf();
(****pf)();
(***************f)();
}
7. what does it return?
return ((1 - sizeof(int)) >> 32);