考虑iam创建两个变量
char a1,b1,c1; /*consider that im assigning*/
a1='a',b1='b';
/* now i want to combine a1 and b1 and assign to c1
i.e c1='ab' pls suggest me the code to do that.
Dont suggest any complex code im a begineer.
答案 0 :(得分:3)
您无法使用常规char
变量。要做你想做的事,你应该使用char
:
char a1, b1, c1[2];
a1 = 'a';
b1 = 'b';
c1[0] = a1;
c1[1] = b1;
答案 1 :(得分:1)
您无法在char variable
中存储两个字符(它只有1个字节)。
使用char数组并使用sprintf
或snprintf
-
char c1[3];
sprintf(c1,"%c%c",a,b); // or snprintf(c1,sizeof c1,"%c%c",a,b);