Arrays And Strings - Study Mode
[#126] What will be the output of the program? #include<stdio.h>
#include<string.h>
void main()
{
char str1[20] = "Hello", str2[20] = " World"
printf("%s", strcpy(str2, strcat(str1, str2)))
}
Correct Answer
(A) Hello World
Explanation
Solution: >> char str1[20] = "Hello", str2[20] = " World"
The variable str1 and str2 is declared as an array of characters and initialized with value "Hello" and " World" respectively. >> printf ( " %s n ", strcpy ( str2, strcat ( str1, str2 )))
=> strcat (str1, str2) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains "Hello World". => strcpy (str2, "Hello World") it copies the "Hello World" to the variable str2. Hence it prints "Hello World".
[#127] What will be the output of the program? #include<stdio.h>
void main()
{
printf(5+"Good Morningn")
}
Correct Answer
(D) Morning
Explanation
Solution: printf(5+"Good Morning
")
It skips the 5 characters and prints the given string. Hence the output is "Morning".
[#128] What will be the output of the program? #include<stdio.h>
#include<string.h>
void main()
{
char str[] = "Examx00Veda"
printf("%s", str)
}
Correct Answer
(A) Exam
Explanation
Solution: A string is a collection of characters terminated by 'x00'. >> char str[] = "Examx00Vedax00"
The variable str is declared as an array of characters and initialized with value "Exam". >> printf ("%s", str)
It prints the value of the str. The output of the program is "Exam".
[#129] What is the return value of the following statement if it is placed in C program? strcmp("ABC", "ABC")
Correct Answer
(D) 0
Explanation
Solution: strcmp(s1, s2)
returns int as follows: == 0, when s1 == s2 < 0, when s1 < s2 > 0, when s1 > s2
[#130] What will be the output of the following C code? int ch= ' '
if(isgraph(ch))
printf("ch = %c can be printed
",ch)
else
printf("ch=%c cannot be printed
",ch)
Correct Answer
(B) ch = ' ' cannot be printed