Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: String

Home > C Programming > String > General Questions

1. What is the output of the following problem ?

#include
int main()
{
char *c;
c = "Hello";
printf("%s\n", c);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

2. What is the output of the following problem ?

#include
int main()
{
char *str = "12345";
printf("%c %c %c\n", *str, *(str++), *(str++));
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

3. What is the output of the following problem ?

#include
int main()
{
int len=4;
char *st="12345678";
st = st + len;
printf("%c\n",*st);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

4. int main()
{
char string[]="Hello World";
display(string);
return 0;
}
void display(char *string)
{
printf("%s",string);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option E

Explanation:

In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

Workspace

Tags:

No Tags on this question yet!

5. #include
void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("Value of i %d\n",++i);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, but after the pre- increment in the printf statement, value of I will be printed.

Workspace

Tags:

No Tags on this question yet!

6. #include
void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok Done \n");
else
printf("Forget it\n");
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true, thus "Ok
Done" will be printed.

Workspace

Tags:

No Tags on this question yet!

7. What is the output of the following 'C' program ?

#include
void main()
{
char str1[] = "Hello";
char str2[] = "Hello";
if (str1 == str2)
printf("\nequal");
else
printf("\nUnequal");
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

8. What is the output of the following C Program?

#include
#include
void main() {
int i, n;
char *x = "girl";
n = strlen(x);
*x = x[n];
for(i=0; i {
printf("%s\n",x);
x++;
}}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

9. #include
#include
void main()
{
while (strcmp("some","some\0"))
printf("Strings are not equal\n");
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Ending the string constant with \0 explicitly makes no difference.
So "some" and "some\0" are equivalent. So, strcmp returns 0 .
So breaking out of the while loop.

Workspace

Tags:

No Tags on this question yet!

10. #include
void main()
{
char str1[] = {'s','o','m','e'};
char str2[] = {'s','o','m','e','\0'};
while (strcmp(str1,str2))
printf("Strings are not equal\n");
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

If a string constant is initialized explicitly with characters, '\0' is not appended automatically to the string.
Since str1 doesn't have null termination, it treats whatever the values that are in the following positions as part of the string until it randomly reaches a '\0'. So str1 and str2 are not the same.

Workspace

Tags:

No Tags on this question yet!