while(*p!='\0' && *q!='\0')
{
if(*p==*q)
{
p++;
q++;
c++;
}
else
break;
}
Run Code Online (Sandbox Code Playgroud)
我用三元运算符编写了这个,但为什么它给break语句提供错误?
*p==*q?p++,q++,c++:break;
Run Code Online (Sandbox Code Playgroud)
gcc编译器给出了这个错误:'break'之前的预期表达式
我们知道指针的大小取决于地址总线,那么80位的8位微控制器上的指针大小是多少?
#include<stdio.h>
char *concat(char *p1,char *); //function decalaration
int main(void)
{
char a[100],b[100],*q=NULL; //declare two char arrays
printf("Enter str1:");
scanf("%s",a);
printf("Enter str2:");
scanf("%s",b);
q=concat(a,b); //calling str concat function
printf("Concatenated str:%s\n",q);
return 0;
}
char *concat(char *p1,char *p2) //function to concatenate strings
{
while(*p1!='\0')
p1++;
while(*p2!='\0')
{
*p1=*p2;
p1++;
p2++;
}
*p1='\0';
printf("Concatenated str=%s\n",p1); //printing the concatenated string
return p1; //returning pointer to called function
}
Run Code Online (Sandbox Code Playgroud)
//虽然逻辑是正确的,但它没有显示输出.//为什么这段代码不起作用?
在下面的代码中:
#include<stdio.h>
int main(void)
{
printf("%d",sizeof(int));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在gcc(Ubuntu 4.8.4-2ubuntu1~14.04.3)4.8.4编译器上编译时,它会发出警告:
格式'%d'需要类型为'int'的参数,但参数2的类型为'long unsigned int'[ - Wformat =] printf("%d",sizeof(int));
为什么我收到这个警告?是返回类型的sizeof是'long unsigned int'吗?
当我用'%ld'替换'%d'时警告就开始了.