|
C and C++ Interview Questions |
18. What is the difference between "printf(...)" and "sprintf(...)"?
Ans:
sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.
|
Ex - 1: what is the output of the following code?
#include<stdio.h>
void main()
{
printf("%d",printf(" hello world "));
}
a) 13, b) hello world 13, c) hello world, d) error
Ans: b
|
Ex - 2: what will print out?
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%sn”,p2);
}
Ans:empty string.
|
|
|