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

C Programming Questions and Answers on Precedence and Order of Evaluation – 1 for Freshers

1. Which of the following operators has an associativity from Right to Left? a) <=b) <<c) ==d) += Answer: d 2. Which operators of the following have same precedence? P. "!="...

Java Multiple Choice Questions & Answers on Class Fundamentals & Declaring objects for Freshers

1. What is the stored in the object obj in following lines of code?box obj; a) Memory address of allocated memory of object.b) NULLc) Any arbitrary pointerd) Garbage Answer: b Explanation: Memory...

Oracle Database Multiple Choice Questions and Answers on Planning Oracle Applications – Approaches, Risks and Standards for Freshers

1. Database management systems are intended to _____________ a) Eliminate data redundancyb) Establish relationship among records in different filesc) Manage file accessd) All of the Mentioned Answ...

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