C Programming Multiple Choice Questions and Answers on String Operations for Freshers

1. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world";
  5.         char *str1 = "hello, world";
  6.         if (strcmp(str, str1))
  7.             printf("equal");
  8.         else
  9.             printf("unequal");
  10.     }
a) equal
b) unequal
c) Compilation error
d) Depends on the compiler
Answer: b
2. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello";
  5.         char str1[5];
  6.         strcpy(str, str1);
  7.         printf("%s", str1);
  8.     }
a) Compilation error
b) Undefined behaviour
c) hello, world
d) hello, wo 9
Answer: d
3. What is the output of this C code?
  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char *str = "hello, world";
  6.         char str1[9];
  7.         strncpy(str1, str, 9);
  8.         printf("%s %d", str1, strlen(str1));
  9.     }
a) hello, world 11
b) hello, wor 9
c) Undefined behaviour
d) Compilation error
Answer: c
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world\n";
  5.         printf("%d", strlen(str));
  6.  
  7.     }
a) Compilation error
b) Undefined behaviour
c) 13
d) 11
Answer: c
5. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char str[11] = "hello";
  5.         char *str1 = "world";
  6.         strcat(str, str1);
  7.         printf("%s %d", str, str[10]);
  8.     }
a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash
Answer: a
6. Strcat function adds null character

a) Only if there is space
b) Always
c) Depends on the standard
d) Depends on the compiler
Answer: b
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char str[10] = "hello";
  5.         char *str1 = "world";
  6.         strncat(str, str1, 9);
  7.         printf("%s", str);
  8.     }
a) helloworld
b) Undefined behaviour
c) helloworl
d) hellowor
Answer: a
8. The return-type used in String operations are.

a) void only
b) void and (char *) only
c) void and int only
d) void, int and (char *) only
Answer: d
9. String operation such as strcat(s, t), strcmp(s, t), strcpy(s, t) and strlen(s) heavily     rely upon.

a) Presence of NULL character
b) Presence of new-line character
c) Presence of any escape sequence
d) None of the mentioned
Answer: a
10. Which pre-defined function returns a pointer to the last occurence of a character in     a string?

a) strchr(s, c);
b) strrchr(s, c);
c) strlchr(s, c);
d) strfchr(s, c);
Answer: b
11. Which of the following function compares 2 strings with case-insensitively?

a) strcmp(s, t)
b) strcmpcase(s, t)
c) strcasecmp(s, t)
d) strchr(s, t)
Answer: c
12. What will be the value of var for the following?
    var = strcmp(“Hello”, “World”);

a) -1
b) 0
c) 1
d) strcmp has void return-type
Answer: a
13. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char str[10] = "hello";
  5.         char *p = strrchr(str, 'l');
  6.         printf("%c\n", *(++p));
  7.     }
a) l
b) o
c) e
d) Compilation error
Answer: b

Related

Java Multiple Choice Questions & Answers on Java.io Character Streams for Freshers

1. Which of these stream contains the classes which can work on character stream? a) InputStreamb) OutputStreamc) Character Streamd) All of the mentioned Answer: C Explanation: InputStream & ...

CSS Multiple Choice Questions & Answers on Document Structure and CSS Inheritance for Freshers

1. If a particular rule should never be overridden by another rule, the ____________ indication should be used. a) @important b) !important! c) !important d) important! Answer: c ...

C Programming Questions and Answers on Character Pointers and Functions for Freshers

1. What is the output of this C code? #include int main() { char *str = "hello, world\n"; char *strc = "good morning\n"; strcpy(strc, str); ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item