Sunday, April 26, 2020

MCQs C String Set - 2 Answer

MCQs C String Set - 2 Answer



The _________ string function can be used to read multiple words from user.
A. getc()
B. gets()
C. getchar()
D. getche()
ANSWER: B. gets()

Which of the following string function can be used to copy n characters from one string to another string?
A. strncpy
B. strcat
C. strncat
D. strlen
ANSWER: A. strncpy

What will be the output of following C program?
#include<stdio.h>
#include<string.h>
int main(){
  char state[20]="Gujarat India";
  printf("%d", strlen(state));
  return 0;
}
A. 13
B. 14
C. 20
D. none of these
ANSWER: A. 13

What will be the output of following C program?
#include<stdio.h>
#include<string.h>
int main() {
    char fname[20] = "K";
    char sname[20] = "Patel";
    printf("%s\n", strcpy(strcat(fname, sname), sname));
    return 0;
}
A. K Patel
B. Patel
C. K
D. none of these
ANSWER: B. Patel

What will be the output of following C program?
#include<stdio.h>
#include<string.h>
int main(){
    char str1[30] = "C Programming";
    char str2[30] = "Top C Practicals";
    printf("%s", strncpy(str1, str2, 16));
    return 0;
}
A. Top C Practicals
B. C Programming Top C Practicals
C. C Programming Top
D. none of these
ANSWER: A. Top C Practicals

Back to Questions Bank >



MCQs C String - Set 2

MCQs C String - Set 2



Question 1. The _________ string library function can be used to read multiple words from user. 
A. getc()
B. gets()
C. getchar()
D. getche()

Question 2. Which of the following string function can be used to copy n characters from one string to another string? 
A. strncpy() 
B. strcat() 
C. strncat() 
D. strlen

Question 3. What will be the output of following C program?

#include<stdio.h>
#include<string.h>
int main(){
  char state[20]="Gujarat India";
  printf("%d", strlen(state));
  return 0;

}
A. 13
B. 14 
C. 20
D. none of these

Question 4. What will be the output of following C program?

#include<stdio.h>
#include<string.h>
int main()
{
    char fname[20] = "K";
    char sname[20] = "Patel";
    printf("%s\n", strcpy(strcat(fname, sname), sname));
    return 0;
} 
A. K Patel 
B. Patel 
C. K 
D. none of these

Question 5. What will be the output of following C program?


#include<stdio.h>
#include<string.h>
int main(){
    char str1[30] = "C Programming";
    char str2[30] = "Top C Practicals";
    printf("%s", strncpy(str1, str2, 16));
    return 0;
}
A. Top C Practicals 
B. C Programming Top C Practicals 
C. C Programming Top 
D. none of these

   

Score out of 5 =   Percentage =


Check Your Answer Here

Back to Questions Bank >