Persistent
Company
Category
#include
func(char *s1,char * s2)
{
char *t;
t=s1;
s1=s2;
s2=t;
}
int main()
{
char *s1="jack", *s2="jill";
func(s1,s2);
printf("
%s
%s ",s1,s2);
return 0;
}
Read Solution (Total 7)
-
- The correct output is jackjill (since it is just following call by value mechanism).
To get output jill jack the following is the code :-
#include
func(char **s1,char **s2)
{
char *t;
t=*s1;
*s1=*s2;
*s2=t;
}
int main()
{
char *s1="jack", *s2="jill";
func(&s1,&s2);
printf("%s %s ",s1,s2);
return 0;
}
- 9 years agoHelpfull: Yes(15) No(0)
- again function is not reyrning anything so the answr is jack jill,,,,,but if we print within the function then it must be jill jack :)
- 10 years agoHelpfull: Yes(8) No(0)
- jack jill
- 10 years agoHelpfull: Yes(2) No(4)
- jack jill cause its call by value not call by reference
- 9 years agoHelpfull: Yes(2) No(0)
- jackjill
it will just print both the string jack and jill. Coz int the function func we are just assining jack again in s1 - 10 years agoHelpfull: Yes(1) No(0)
- Initially s1 =jack and s2=jill,then if func() the s1 value is stored in t and s2 value is stored in s1 so here s1=jill and again t value is stored in s2 so here s2=jack.
Ans= jill jack. - 6 years agoHelpfull: Yes(1) No(0)
- wont it b jill jack??
- 10 years agoHelpfull: Yes(0) No(7)
Persistent Other Question
what is int(*(*ptr (int))(void)
void main()
{
int a[5] ={1,2,3,4,5},i,j=2,b;
for (i =0;i<5;i++ )
func(j,a[i]);
for (i =0;i<5;i++ )
printf(?%d?,a[i]);
}
func(int j,int *a)
{
j=j+1;
a=a+j;
b= b+2;
}