Find output of C programs (strings) | Set 2
belongs to collection: Find output of programs in C
All Answers
Answer 1:
Output
-1 , 0 , 1
Explanation
In C the function strcmp() works by comparing each character of both strings. It compares until a different word is found.
If ASCII value of word of 1st string is greater than ASCII value of word of 2ndstring then the output is 1.
Similarly, If ASCII value of word of 1st string is smaller than ASCII value of word of 2nd string then the output is -1.
Answer 2:
strrchr()
Explanation
In C function strrchr() is used to find the last occurrence of character.
Example:
#include <stdio.h>
#include <string.h>
int main()
{
char document[] = "I love IncludeHelp.com This is an amazing website ";
char *s, *p ;
char character2 = 'x', character1 = 't';
s = strrchr(document, character1 );
p = strrchr(document, character2 );
if (s)
printf("The position of '%c' is %d\n", character1, s-document);
else
printf("The character was not found in given document\n");
if (p)
printf("The position of '%c' is %d\n", character2 , p-document);
else
printf("The character was not found in given document\n");
return 0;
}
Output
The position of 't' is 47 The character was not found in given document
Answer 3:
Output
85
Explanation
Here, a is a character array that contains "%d\n", this final statement after execution will be considered like printf("%d\n",85); thus, output will be 85.
Answer 4:
Output
13, 8, 1, 1
Explanation
sizeof(a) will return 13 because total number of characters are 13 (including NULL character).
sizeof(b) will return 8 (depending on the compiler architecture, here b is a pointer and pointer takes 8 bytes in the memory as they hold the memory address, and the memory address size depends on the compiler architecture.
sizeof(*a) and sizeof(*b) will return 1 and 1, because *a and *b are representing the single character and in C language character size is 1 byte.
need an explanation for this answer? contact us directly to get an explanation for this answertotal answers (2)
Answer 1:
Output
Explanation
In C the function strcmp() works by comparing each character of both strings. It compares until a different word is found.
If ASCII value of word of 1st string is greater than ASCII value of word of 2ndstring then the output is 1.
Similarly, If ASCII value of word of 1st string is smaller than ASCII value of word of 2nd string then the output is -1.
Answer 2:
Explanation
In C function strrchr() is used to find the last occurrence of character.
Example:
Output
Answer 3:
Output
Explanation
Here, a is a character array that contains "%d\n", this final statement after execution will be considered like printf("%d\n",85); thus, output will be 85.
Answer 4:
Output
Explanation
sizeof(a) will return 13 because total number of characters are 13 (including NULL character).
sizeof(b) will return 8 (depending on the compiler architecture, here b is a pointer and pointer takes 8 bytes in the memory as they hold the memory address, and the memory address size depends on the compiler architecture.
sizeof(*a) and sizeof(*b) will return 1 and 1, because *a and *b are representing the single character and in C language character size is 1 byte.
need an explanation for this answer? contact us directly to get an explanation for this answer