0% found this document useful (0 votes)
45 views2 pages

#Include #Include: Int Char Int

The program compares two strings entered by the user using the strcmp() function. Strcmp() returns an integer value that is unpredictable based on the string values. It then prints this integer value. Therefore, the output of the program is an unpredictable integer value. The second program declares a variable X with value 40, then another variable X with value 20 within inner braces. It prints the inner X with value 20, then the outer X with value 40, so the output is 20 40.

Uploaded by

ayushi mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

#Include #Include: Int Char Int

The program compares two strings entered by the user using the strcmp() function. Strcmp() returns an integer value that is unpredictable based on the string values. It then prints this integer value. Therefore, the output of the program is an unpredictable integer value. The second program declares a variable X with value 40, then another variable X with value 20 within inner braces. It prints the inner X with value 20, then the outer X with value 40, so the output is 20 40.

Uploaded by

ayushi mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. 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;
}

1. Unpredictable integer value


2. 0
3. -1
4. Error

Correct Answer: Option A


Explanation:
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("%d\n", i); It prints the value of variable i.

2. What will be the output of the program?


#include<stdio.h>
int main()
{
int X=40;
{
int X=20;
printf("%d ", X);
}
printf("%d\n", X);
return 0;
}

You might also like