In: Computer Science
1.) Answer the following programs
a.) Let f be the following function:
int f(char *s, char *t)
{
char *p1, *p2;
for(p1 = s, p2 = t; *p1 != '\0'&& *p2 != '\0'; p1++, p2++){
if (*p1 == *p2) break;
}
return p1 -s;
}
What is the return value of f(“accd”, “dacd”)?
b.) What will be the output of the below program?
#include <stdio.h>
int main()
{
char x[]="ProgramDesign", y[]="ProgramDesign";
if(x==y){
printf("Strings are Equal");
}
Question a:
Answer:2
Explanation :
Below screen shows the output
*******************************************
Question b:
Answer :Nothing will be printed
Explanation :
Below screen shows the output
Below screen shows the output when strcmp() is used.