1.某公司2019秋招在线笔试题 ;联合体union
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
union var
{
int a ;
char m[5];
int *p;
};
void test()
{
printf("%d\n ",sizeof( union var));
}
int main()
{
test();
system("pause");
return 0;
}
结果 :8
2.字符翻转 将字符串 student a am i或 ( I Am Prammer) 翻转为 i am a student或(Prammer Am I)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
void ReverseStringCode(char *start, char *end)//一小段字符翻转
{
assert(start);
assert(end);
while (start < end)
{
*start ^= *end;
*end ^= *start;
*start ^= *end;
start++;
end--;
}
}
void ChangeString(char a[])//以空格划分,逐段翻转
{
//assert(a);
char *p = a;
char *prev = p;
while (*p)
{
if (*p == ' ')
{
ReverseStringCode(prev, p - 1);
p++;
prev = p;
continue;
}
p++;
}
ReverseStringCode(prev, p - 1);//翻转最后一个字符
ReverseStringCode(a, p - 1);//整体翻转
}
void test01()// 将字符串 student a am i ( I Am Prammer) 翻转为 i am a 、、 student(Prammer Am I)
{
char a[] = " I Am Prammer";
printf("before: %s\n", a);
ChangeString(a);
printf("after: %s\n", a);
system("pause");
return 0;
}
int main()
{
test01();
system("pause");
return 0;
}