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

HTML Multiple Choice Questions & Answers on Compatibility Libraries for Freshers

1. Which one of the following is an open source JavaScript library that enables styling for HTML5 elements in versions of Internet Explorer before IE 9 ? a) HTML5b) HTML5 Shivc) HTML5 Shimd) None o...

Java Multiple Choice Questions & Answers on Searching & Modifying a String for Freshers

1. Which of these method of class String is used to extract a substring from a String object? a) substring()b) Substring()c) SubString()d) None of the mentioned Answer: a 2. What will s2 contain ...

CSS Multiple Choice Questions & Answers on Backgrounds, Borders and Drop Shadow for Freshers

1. Which of the following property sets the background image to scroll or not to scroll with its associated element’s content? a) background-scrollb) background-attachc) background-attachmentd) bac...

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