include<conio.h>
include<string.h>
void main{
char str[100]="this is logic practice with c and java";
char *sub;
clrscr;
sub=strstr(str,"java");
printf("\n %s",sub);
getch;
}
- this is logic practice with c and java
- logic practice with c and java
- java
- compile error
The correct option is (b).
Explanation:
The strstr() function returns pointer to the first occurrence of the matched string in the given string. It is used to return substring from first match till the last character.
Syntax:
char *strstr(const char *string, const char *match)
string: It represents the full string from where substring will be searched.
match: It represents the substring to be searched in the full string.
Therefore the output of the above program is logic practice with c and java.
## 17) What will be the output of the below program?
include<stdio.h>
main
{
char x = "Hi\0Hello";
printf("%d %d", strlen(x), sizeof(x));
}
- 9 20
The correct option is (c).
Explanation:
The strlen(x) function is used for finding the length of string 'x'. In program the length of string is count of character upto '\0'. Hence the string length output is 2.
The sizeof(x) function is used for finding the size of string 'x'. In program sizeof() returns the size of the complete array. Hence the size of array output is 9.
Therefore the combined output of the program is 2 9.
## 18) If the size of pointer is 4 bytes then what will be the output of below program?
include<stdio.h>
int main
{
char *stri = {"Java", "C", "Android", "Embedded", "JS"};
printf("%d, %d", sizeof(stri), strlen(stri[0]));
return 0;
}
- 22, 4
- 20, 4
- 20, 5
- 25,4
The correct option is (b).
Explanation:
Step 1: char *stri[] = {"Java", "C", "Android", "Embedded", "JS"}; The variable stri is declaraed as a pointer to the array of 5 strings.
Step 2: printf("%d, %d", sizeof(stri), strlen(stri[0]));
Sizeof(stri) denotes 5*4 bytes=20 bytes. Hence it prints '20'
Strlen(stri[0]) becomes strlen(Java). Hence it prints '4'.
Hence the output of the program is 20, 4.
## 19) What will be the output of below program?
include<stdio.h>
include<string.h>
int main
{
printf("%c\n", "logic practice"[5]);
return 0;
}
- Compile error
The correct option is (c).
Explanation:
The statement printf("%c\n", "logic practice"[5]); prints the 6th character of the string "logic practice".
Hence the output of a program is 'p'.
## 20) What will be the output of the below program in 16 bit platform assuming that 2022 is memory address of the string "Welcome" (in Turbo C under DOS)?
include<stdio.h>
int main
{
printf("%u %s\n", &"Welcome", &"Programming");
return 0;
}
- 2022 Programming
- Welcome Programming
- Welcome 2022
- Compile error
The correct option is (a).
Explanation:
In a statement like printf("%u %s\n", &"Greetings", &"Coding");
The %u format specifier instructs the compiler to display the memory location of the string "Welcome".
The %s format specifier instructs the compiler to display the text "Programming".
Therefore, the result produced by the code is "2022 Programming".