LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C Programming
  • Strings

C Programming

STRINGS MCQs

Total Questions : 37

Page 1 of 4 pages
Question 1.

Which of the following statement is correct?


  1.    strcmp(s1, s2) returns a number less than 0 if s1>s2
  2.    strcmp(s1, s2) returns a number greater than 0 if s1
  3.    strcmp(s1, s2) returns 0 if s1==s2
  4.    strcmp(s1, s2) returns 1 if s1==s2
 Discuss Question
Answer is Option C. -> strcmp(s1, s2) returns 0 if s1==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

From the above statements, that the third statement is only correct.

Question 2.

Which of the following statements are correct ?
1:A string is a collection of characters terminated by ''.
2:The format specifier %s is used to print a string.
3:The length of the string can be obtained by strlen().
4:The pointer CANNOT work on string.


  1.    1, 2
  2.    1, 2, 3
  3.    2, 4
  4.    3, 4
 Discuss Question
Answer is Option B. -> 1, 2, 3

Clearly, we know first three statements are correct, but fourth statement is wrong. because 

we can use pointer on strings. 

Question 3.

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".


  1.    1, 2
  2.    2, 3, 4
  3.    3, 4
  4.    2, 3
 Discuss Question
Answer is Option B. -> 2, 3, 4

No answer description available for this question. 

Question 4.


Which of the following statements are correct about the program below?



#include<stdio.h>

int main()
{
char str[20], *s;
printf("Enter a string\n");
scanf("%s", str);
s=str;
while(*s != '\0')
{
if(*s >= 97 && *s
  1.    The code converts a string in to an integer
  2.    The code converts lower case character to upper case
  3.    The code converts upper case character to lower case
  4.    Error in code
 Discuss Question
Answer is Option B. -> The code converts lower case character to upper case

This program converts the given string to upper case string.

Question 5.


What will be the output of the following program in 16 bit platform assuming that
1022 is memory address of the string "Hello1" (in Turbo C under DOS) ?



#include<stdio.h>

int main()
{
printf("%u %s\n", &"Hello1", &"Hello2");
return 0;
}



  1.    1022 Hello2
  2.    Hello1 1022
  3.    Hello1 Hello2
  4.    1022 1022
  5.    Error
 Discuss Question
Answer is Option A. -> 1022 Hello2

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".

Question 6.


What will be the output of the program ?



#include<stdio.h>
#include<string.h>

int main()
{
printf("%c\n", "abcdefgh"[4]);
return 0;
}


  1.    Error
  2.    d
  3.    e
  4.    abcdefgh
 Discuss Question
Answer is Option C. -> e

printf("%c`setminus`n", "abcdefgh"[4]); It prints the 5 character of the string "abcdefgh".

Hence the output is 'e'.

Question 7.


What will be the output of the program ?



#include<stdio.h>
int main()
{
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2)
printf("Equal\n");
else
printf("Unequal\n");
return 0;
}

  1.    Equal
  2.    Unequal
  3.    Error
  4.    None of above
 Discuss Question
Answer is Option B. -> Unequal

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".

Question 8.


What will be the output of the program ?



#include<stdio.h>
#include<string.h>

int main()
{
char str1[5], str2[5];
int i;
gets(str1);
gets(str2);
i = strcmp(str1, str2);
printf("%d\n", i);
return 0;
}



  1.    Unpredictable integer value
  2.    0
  3.    -1
  4.    Error
 Discuss Question
Answer is Option A. -> Unpredictable integer value

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.

Question 9.


What will be the output of the program ?



#include<stdio.h>
int main()
{
int i;
char a[] = "\0";
if(printf("%s", a))
printf("The string is not empty\n");
else
printf("The string is empty\n");
return 0;
}

  1.    The string is not empty
  2.    The string is empty
  3.    No output
  4.    0
 Discuss Question
Answer is Option B. -> The string is empty

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".

Question 10.


If the size of pointer is 4 bytes then What will be the output of the program ?



#include<stdio.h>
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}



  1.    22, 4
  2.    25, 5
  3.    24, 5
  4.    20, 2
 Discuss Question
Answer is Option C. -> 24, 5

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).

  • 1
  • 2
  • 3
  • 4
  • Next →
  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Arrays
  • Bitwise Operators
  • C Preprocessor
  • Command Line Arguments
  • Complicated Declarations
  • Const
  • Control Instructions
  • Declarations And Initializations
  • Expressions
  • Floating Point Issues
  • Functions
  • Input / Output
  • Library Functions
  • Memory Allocation
  • Pointers
  • Strings
  • Structures
  • Subleties Of Typedef
  • Variable Number Of Arguments

Recent Posts

  • Quantitative Aptitude Faqs
  • Sail E0 Exam Results Cancelled - Exam Will Be Rescheduled
  • Vedic Maths Faq
  • Ssc Exam Guide Book
  • Sail E0 Results 2022
  • Is Ssc Difficult Than Upsc?
  • Best Ssc Exam For Girls

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....

Topics

Computer Aptitude
SAIL Junior Officer (E-0)
10th Grade
11th Grade
12th Grade
4th Grade
5th Grade
6th Grade
7th Grade
8th Grade
9th Grade
NCERT
Cat
Commerce
Computer Science
Engineering
English
General Knowledge
Ias
Management
Quantitative Aptitude
Reasoning Aptitude
General Studies (Finance And Economics)
Analytical Instrumentation
Biochemistry
Bioinformatics
Biology
Biotechnology
Bitsat
Business Statistics
C Programming
C++ Programming
Cell Biology
Chemistry
Cost Accounting
Drug And Pharmaceutical Biotechnology
Electrical Measurement And Instrumentation
Environment Management
Environmental Biotechnology
Enzyme Technology
Financial Management And Financial Markets
Gate
General Science
Geography
Heat Transfer
History And National Movements
Human Anatomy And Physiology
Human And Cultural Diversity
Human Resource Management
Indian Economy
Indian Geography
Indian History
Indian Polity
Instrumentation Transducers
International Relations
Life Sciences
Marketing And Marketing Management
Mass Transfer
Mechanics Of Materials
Microbiology
Neet
Professional Communication
Renewable Energy
Sociology
Surveying
Total Quality Management
Uidai Aadhaar Supervisor Certification
Virology
LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password