Predict the output of the following coding question on C language:
1. Find the output of the following code?
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
2. Find the output of the following code?
void main()
{
char *str = "hello";
char str1[5];
strcpy(str1, str);
printf("%s", str1);
}
3. Find the output of the following code?
void main()
{
char *str = "hello, world";
char str1[9];
strncpy(str1, str, 9);
printf("%s %d", str1, strlen(str1));
}
4. Find the output of the following code?
int xstrlen(char *s)
{
int length=0;
while(*s!='\0')
{
length++;
s++;
}
return (length);
}
5. Find the output of the following code?
int main()
{
char str1[20] = "C ", str2[20] = "Programming";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
6. Find the output of the following code?
int main()
{
char *names[] = { "A", "B", "C", "D", "E"};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for(i=0; i<=4; i++)
printf("%s\t", names[i]);
return 0;
}
7. Find the output of the following code?
int main()
{
static char str1[] = "C";
static char str2[20];
static char str3[] = "Programming";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "Computers");
printf("%d\n", i);
return 0;
}
8. Find the output of the following code?
int main()
{
static char s[] = "Hello!";
printf("%d\n", *(s+strlen(s)));
return 0;
}
Post A Comment:
0 comments: