Sail E0 Webinar

MCQs

Total Questions : 37 | Page 3 of 4 pages
Question 21.


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
static char str1[] = "dills";
static char str2[20];
static char str3[] = "Daffo";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
printf("%d\n", i);
return 0;
}
  1.    0
  2.    1
  3.    2
  4.    4
 Discuss Question
Answer: Option A. -> 0

No answer description available for this question. 


Question 22.


What will be the output of the program ?


#include<stdio.h>
int main()
{
char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for(i=0; i
  1.    Suresh, Siva, Sona, Baiju, Ritu
  2.    Suresh, Siva, Sona, Ritu, Baiju
  3.    Suresh, Siva, Baiju, Sona, Ritu
  4.    Suresh, Siva, Ritu, Sona, Baiju
 Discuss Question
Answer: Option B. -> Suresh, Siva, Sona, Ritu, Baiju

Step 1: char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"}; The variable names 

is declared as an pointer to a array of strings.

Step 2: int i; The variable i is declared as an integer type.

Step 3: char *t; The variable t is declared as pointer to a string.

Step 4: t = names[3]; names[3] = names[4]; names[4] = t; These statements the swaps

 the 4 and 5 element of the array names.

Step 5: for(i=0; i<=4; i++) printf("%s,", names[i]); These statement prints the all the value 

of the array names.

Hence the output of the program is "Suresh, Siva, Sona, Ritu, Baiju".


Question 23.


What will be the output of the program If characters 'a', 'b' and 'c'
enter are supplied as input?


#include<stdio.h>
int main()
{
void fun();
fun();
printf("\n");
return 0;
}
void fun()
{
char c;
if((c = getchar())!= '\n')
fun();
printf("%c", c);
}
  1.    abc abc
  2.    bca
  3.    Infinite loop
  4.    cba
 Discuss Question
Answer: Option D. -> cba

Step 1: void fun(); This is the prototype for the function fun().

Step 2: fun(); The function fun() is called here.

The function fun() gets a character input and the input is terminated by an enter key

(New line character). It prints the given character in the reverse order.

The given input characters are "abc"

Output: cba


Question 24.


What will be the output of the program ?


#include<stdio.h>
int main()
{
printf(5+"Good Morning\n");
return 0;
}
  1.    Good Morning
  2.    Good
  3.    M
  4.    Morning
 Discuss Question
Answer: Option D. -> Morning

printf(5+"Good Morning`setminus`n"); It skips the 5 characters and prints the given string.

Hence the output is "Morning"


Question 25.


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
printf("%d\n", strlen("123456"));
return 0;
}
  1.    6
  2.    12
  3.    7
  4.    2
 Discuss Question
Answer: Option A. -> 6

The function strlen returns the number of characters in the given string.

Therefore, strlen("123456") returns 6.

Hence the output of the program is "6".


Question 26.


What will be the output of the program ?


#include<stdio.h>
int main()
{
char p[] = "%d\n";
p[1] = 'c';
printf(p, 65);
return 0;
}
  1.    A
  2.    a
  3.    c
  4.    65
 Discuss Question
Answer: Option A. -> A

Step 1: char p[] = "%d`setminus`n"; The variable p is declared as an array of characters and

 initialized with string "%d".

Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array

 p becomes "%c".

Step 3: printf(p, 65); becomes printf("%c", 65);

Therefore it prints the ASCII value of 65. The output is 'A'.



Question 27.


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
  1.    Hello
  2.    World
  3.    Hello World
  4.    WorldHello
 Discuss Question
Answer: Option C. -> Hello World

Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and str2 is declared as an array of characters and initialized with value "Hello" and " World" respectively.

Step 2: printf("%s`setminus`n", strcpy(str2, strcat(str1, str2)));

=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains "Hello World".

=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2.

Hence it prints "Hello World".


Question 28.

If the two strings are identical, then strcmp() function returns


  1.    -1
  2.    1
  3.    0
  4.    Yes
 Discuss Question
Answer: Option C. -> 0

Declaration: strcmp(const char *s1, const char*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


Question 29.

Which of the following function sets first n characters of a string to a given character?


  1.    strinit()
  2.    strnset()
  3.    strset()
  4.    strcset()
 Discuss Question
Answer: Option B. -> strnset()


Declaration:
char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch


#include<stdio.h>
#include<string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf("string before strnset: %s\n", string);
strnset(string, letter, 13);
printf("string after strnset: %s\n", string);
return 0;
}


Output:
string before strnset: abcdefghijklmnopqrstuvwxyz
string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz


Question 30.

What will be output if you compile following c code ?


void main()
{
int const SIZE=5;
int expr;
double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
expr=1|2|3|4;
printf("%f",value[expr]);
}


  1.    2.000000
  2.    4.000000
  3.    8.000000
  4.    Compile Errror
 Discuss Question
Answer: Option D. -> Compile Errror

Size of any array in c cannot be
constantan variable.



Latest Videos

Latest Test Papers