Strings - Find Output of Program Multiple Questions and Answers.
Exercise Questions ::
Strings
16. If the size of pointer is 32 bits What will be the output of the program ?
#include<stdio.h>
int main()
{
char a[] = "Visual C++" ;
char *b = "Visual C++" ;
printf("%d, %d\n" , sizeof (a), sizeof (b));
printf("%d, %d" , sizeof (*a), sizeof (*b));
return 0 ;
}
A. 10, 2 2, 2 B. 10, 4 1, 2 C. 11, 4 1, 1 D. 12, 2 2, 2
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
17. What will be the output of the program?
#include<stdio.h>
int main()
{
static char mess[6 ][30 ] = {"Don't walk in front of me..." ,
"I may not follow;" ,
"Don't walk behind me..." ,
"Just walk beside me..." ,
"And be my friend." };
printf("%c, %c\n" , *(mess[2 ]+9 ), *(*(mess+2 )+9 ));
return 0 ;
}
A. m, f B. n, k C. k, k D. t, t
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
18. What will be the output of the program?
#include<stdio.h>
int main()
{
char str1[] = "Hello" ;
char str2[10 ];
char *t, *s;
s = str1;
t = str2;
while (*t=*s)
*t++ = *s++;
printf("%s\n" , str2);
return 0 ;
}
A. Hello B. HelloHello C. No output D. olleH
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
19. What will be the output of the program?
#include<stdio.h>
int main()
{
char str[25 ] = "PakMcqs" ;
printf("%s\n" , &str+2 );
return 0 ;
}
A. Garbage value B. No output C. Error D. akMcqs
View Answer
Discuss forum
Workplace
Report
Published by:Michael Daani
20. What will be the output of the program?
#include<stdio.h>
int main()
{
char str = "PakMCQs" ;
printf("%s\n" , str);
return 0 ;
}
A. Base address of str B. PakMCQs C. No Output D. Error
View Answer
Discuss forum
Workplace
Report
Answer: Option D
Explanation:
The line char str = "PakMCQs
"; generates "Non portable pointer conversion" error.
To eliminate the error, we have to change the above line to
char *str = "PakMCQs
"; (or) char str[] = "PakMCQs";
Then it prints "PakMCQs".
See More Information
Tutorial Link:
Published by:Michael Daani
« »