C Programming
STRINGS MCQs
Total Questions : 37
Page 1 of 4 pagesThe 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
From the above statements, that the third statement is only correct.
Clearly, we know first three statements are correct, but fourth statement is wrong. because
we can use pointer on strings.
Which of the following statements are correct about the below declarations?
char *p = "Sanjay";
char a[] = "Sanjay";
1: There is no difference in the declarations and both serve the same purpose.
2: p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing
to a non-const pointer.
3: The pointer p can be modified to point to another string, whereas the individual characters within
array a can be changed.
4: In both cases the '' will be added at the end of the string "Sanjay".
No answer description available for this question.
This program converts the given string to upper case string.
In printf("%u %s`setminus`n", &"Hello", &"Hello");.
The %u format specifier tells the compiler to print the memory address of the "Hello1".
The %s format specifier tells the compiler to print the string "Hello2".
Hence the output of the program is "1022 Hello2".
printf("%c`setminus`n", "abcdefgh"[4]); It prints the 5 character of the string "abcdefgh".
Hence the output is 'e'.
Step 1: char str1[] = "Hello"; The variable str1 is declared as an array of characters
and initialized with a string "Hello".
Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters
and initialized with a string "Hello".
We have use strcmp(s1,s2) function to compare strings.
Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address
of both variable is not same. Hence the if condition is failed.
Step 4: At the else part it prints "Unequal".
gets() gets collects a string of characters terminated by a new line from the standard
input stream stdin.
The gets(str1) read the input string from user and store in variable str1.
The gets(str2) read the input string from user and store in variable str2.
The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other
negative or positive values. So the value of i is "unpredictable integer value".
printf("%dn", i); It prints the value of variable i.
The function printf() returns the number of charecters printed on the console.
Step 1: char a[] = '�'; The variable a is declared as an array of characters and it initialized
with "�". It denotes that the string is empty.
Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero).
Hence the if condition is failed.
In the else part it prints "The string is empty".
Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The variable str is declared
as an pointer to the array of 6 strings.
Step 2: printf("%d, %d", sizeof(str), strlen(str[0]));
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'
strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';
Hence the output of the program is 24, 5
Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5.
Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform),
the output will be 24, 5 (because the size of pointer is 4 bytes).
Recent Questions
Q. Following Is A Set Of Four Sentences. Choose The Sentence Wh....
Q. Which Nutrient Forms Most Of Our Body Weight?
Q. What Is The Name Given To The Specialized Storage Element In....
Q. if The Area Of A Square With The Side A Is Equal To The Ar....
Q. The Following Questions Two Statements Are Given And These S....
Q. The Vitamin Riboflavin Is Part Of The __________ Molecule.
Q. Choose An Appropriate Word From The Options To Suitably Fill....
Q. A Code Which Uses More Bits For Each Character Then What Is ....
Q. Union Minister For Agriculture And Farmers Welfare Shri Nare....
Q. Which Type Of Wildlife Is Found In Ganga-Brahmaputra Delta?
Q. A NOR Gate Recognizes Only The Input Word Whose Bits Are ___....
Q. Gibbs Phase Rule Finds Application, When Heat Transfer Occur....
Q. What Is The Author Trying To Convey By Quoting Phil Knight&a....
Q. When Following System Is Disturbed By Addition Of Nitrogen G....
Q. Electron Affinity Of Halogens Is
Q. __________ Is Used As A Catalyst In Fat Splitting.
Q. The Hot And Cold Deserts Together Occupy Nearly ____ Land Ar....
Q. Electric Locomotives In India Are Manufactured At
Q. The Keyword LIKE Can Be Used In A WHERE Clause To Refer To A....
Q. A Technique For Producing Animation In Which One Image Chang....