ExamVeda
Login
Home
51
If the two strings are identical, then strcmp() function returns
Discuss
Answer & Solution
Answer: Option B
Solution:

Declaration: strcmp(const char *s1, const char*s2);

The strcmp return an int value that is
if s1 < s2 returns a value < 0
if s1 == s2 returns 0
if s1 > s2 returns a value > 0

52
The library function used to find the last occurrence of a character in a string is
Discuss
Answer & Solution
Answer: Option D
Solution:

Declaration: char *strrchr(const char *s, int c);

It scans a string s in the reverse direction, looking for a specific character c.

53
Which of the following function is used to find the first occurrence of a given string in another string?
Discuss
Answer & Solution
Answer: Option C
Solution:

The function strstr() Finds the first occurrence of a substring in another string
Declaration: char *strstr(const char *s1, const char *s2);

Return Value:
On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1).
On error (if s2 does not occur in s1), strstr returns null.

54
Which of the following function is more appropriate for reading in a multi-word string?
Discuss
Answer & Solution
Answer: Option B
Solution:

gets(); collects a string of characters terminated by a new line from the standard input stream stdin

55
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)));
}
Discuss
Answer & Solution
Answer: Option A
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("%sn", 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".
56
What will be the output of the program?
#include<stdio.h>
void main()
{
    printf(5+"Good Morningn");
}
Discuss
Answer & Solution
Answer: Option D
Solution:

printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.
Hence the output is "Morning".

57
What will be the output of the program?
#include<stdio.h>
#include<string.h>
void main()
{
    char str[] = "Exam\0Veda";
    printf("%s", str);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

A string is a collection of characters terminated by '\0'.

>> char str[] = "Exam\0\Veda\0"; 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".

58
Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?
Discuss
Answer & Solution
Answer: Option A
Solution:

Array index always starts with 0.

59
What is the return value of the following statement if it is placed in C program? strcmp("ABC", "ABC");
Discuss
Answer & Solution
Answer: Option D
Solution:

strcmp(s1, s2);
returns int as follows:
== 0, when s1 == s2
< 0, when s1 < s2
> 0, when s1 > s2

60
int a[5] = {1,2,3}
What is the value of a[4]?
Discuss
Answer & Solution
Answer: Option D
Solution:

In the fourth location of an array it contains 0 since default initialization will take place.