Strings - Find Output of Program Multiple Questions and Answers.
Exercise Questions ::
Strings
Answer: Option B
Explanation:
printf("Pak", "Mcqs\n"); It prints "Pak". Because , (comma) operator has Left to Right associativity. After printing "Pak", the statement got terminated.
See More Information
Tutorial Link:
Published by:Michael Daani
7. What will be the output of the program?
#include<stdio.h>
int main()
{
char str[7 ] = "PakMcqs" ;
printf("%s\n" , str);
return 0 ;
}
A. PakMcqs B. Cannot predict C. Error D. None of above
View Answer
Discuss forum
Workplace
Report
Answer: Option B
Explanation:
Here str[] has declared as 7 character array and into a 8 character is stored. This will result in overwriting of the byte beyond 7 byte reserved for '\0' .
See More Information
Tutorial Link:
Published by:Michael Daani
8. What will be the output of the program?
#include<stdio.h>
int main()
{
char *names[] = { "Ali" , "Haider" , "Farhan" , "Aftab" , "Zoha" };
int i;
char *t;
t = names[3 ];
names[3 ] = names[4 ];
names[4 ] = t;
for (i=0 ; i<=4 ; i++)
printf("%s," , names[i]);
return 0 ;
}
A. Ali, Haider, Farhan, Aftab, Zoha B. Ali, Haider, Farhan, Zoha, Aftab C. Ali, Haider, Aftab, Farhan, Zoha D. Aftab, Farhan, Zoha, Ali, Haider
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
9. What will be the output of the program?
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "Pak\0\Mcqs\0" ;
printf("%d\n" , strlen(str));
return 0 ;
}
A. 10 B. 6 C. 3 D. 11
View Answer
Discuss forum
Workplace
Report
Answer: Option C
Explanation:
The function strlen returns the number of characters int the given string.
Therefore, strlen(str) becomes strlen("Pak") contains 3 characters. A string is a collection of characters terminated by '\0'.
The output of the program is "3".
See More Information
Tutorial Link:
Published by:Michael Daani
10. 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 ;
}
A. 0 B. 1 C. 2 D. 4
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
« »