程序员笔试题
1。什么是预编译,何时需要预编译:
2。char * const p
      char const * p
    const char *p
上述三个有什么区别?
3。char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char *str5 = "abc";
const char *str6 = "abc";
char *str7 = "abc";
char *str8 = "abc";

cout << ( str1 == str2 ) << endl;
cout << ( str3 == str4 ) << endl;
cout << ( str5 == str6 ) << endl;
cout << ( str7 == str8 ) << endl;
4。 以下代码中的两个sizeof用法有问题吗?[C易]
void UpperCase( char str[] ) // 将 str 中的小写字母转换成大写字母
{
    for( size_t i=0; i<sizeof(str)/sizeof(str[0]); ++i )笔试题
        if( 'a'<=str[i] && str[i]<='z' )
            str[i] -= ('a'-'A' );
}
char str[] = "aBcDe";
cout << "str字符长度为: " << sizeof(str)/sizeof(str[0]) << endl;
UpperCase( str );
cout << str << endl;
5。一个32位的机器,该机器的指针是多少位
6。main()
{
int a[5]={1,2,3,4,5};
  int *ptr=(int *)(&a+1);
  printf("%d,%d",*(a+1),*(ptr-1));
}
7。请问以下代码有什么问题:
int main()
{
char a;
char *str=&a;
strcpy(str,"hello");
printf(str);
return 0;
}
8。char* s="AAA";
printf("%s",s);
s[0]='B';
printf("%s",s);
有什么错?
9。写一个“标准”宏,这个宏输入两个参数并返回较小的一个。
10。嵌入式系统中经常要用到无限循环,你怎么用C编写死循环。
11。关键字static的作用是什么?
12。关键字const有什么含意
13。关键字volatile有什么含意?并举出三个不同的例子?
14。int (*s[10])(int) 表示的是什么啊?
15。有以下表达式
int a=248; b=4;int const c=21;const int *d=&a;
int *const e=&b;int const *f const =&a;
请问下列表达式哪些会被编译器禁止?为什么?
16交换两个变量的值,不使用第三个变量。即a=3,b=5,交换之后a=5,b=3;
17.c和c++中的struct有什么不同?
18.#include <stdio.h>
#include <stdlib.h>
void getmemory(char *p)
{
    p=(char *) malloc(100);
    strcpy(p,"hello world");
}
int main( )
{
    char *str=NULL;
    getmemory(str);
    printf("%s/n",str);
    free(str);
    return 0;
  }
19.char szstr[10];
strcpy(szstr,"0123456789");
产生什么结果?为什么?
20.列举几种进程的同步机制,并比较其优缺点。