int main()
{
char *a1[10] = {"123","121"};
int i =0;
char *a=NULL;
for(i=0;i<2;i++)
{
a=strcat(a1[i],"0000");
printf("values %s",a);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码的输出为$ ./a.exe值1230000值0000000
但它应该是$ ./a.exe值1230000值1210000
请告诉我我错在哪里
这是代码
#include <stdio.h>
void swap(int *a,int *b)
{
int *tmp;
*tmp=*a;
*a=*b;
*b=*tmp;
}
void main()
{
int i,j;
printf("Enter any number\n");
scanf("%d",&i);
printf("Enter another number\n");
scanf("%d",&j);
printf("Numbers before swap\n");
printf("value of i : %d\n",i);
printf("value of j : %d\n",j);
swap(&i,&j);
printf("Numbers after swap\n");
printf("value of i : %d\n",i);
printf("value of j : %d\n",j);
}
Run Code Online (Sandbox Code Playgroud)
上面一个是我的代码,它工作正常但是当输出在控制台上打印时它会给出Segmentation故障(core dumped)这是o/p
abc:~/Desktop/C$ ./a.out Enter any number 34 Enter another number 54 Numbers before swap value of i : 34 value of j : 54 …
c ×2