Sail E0 Webinar
Question


What will be the output of the program ?


#include<stdio.h>
#include<string.h>
int main()
{
char str1[5], str2[5];
int i;
gets(str1);
gets(str2);
i = strcmp(str1, str2);
printf("%d\n", i);
return 0;
}
Options:
A .  Unpredictable integer value
B .  0
C .  -1
D .  Error
Answer: Option A

gets() gets collects a string of characters terminated by a new line from the standard

 input stream stdin.

The gets(str1) read the input string from user and store in variable str1.

The gets(str2) read the input string from user and store in variable str2.

The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other 

negative or positive values. So the value of i is "unpredictable integer value".

printf("%dn", i); It prints the value of variable i.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers