C - Pointers - Discussion

You Are Here :: Home > C > Pointers - Discussion

 



Q.

What will be output if you will execute following code?

#include
char * call(int *,float *);
int main(){
char *string;
int a=2;
float b=2.0l;
char *(*ptr)(int*,float *);
ptr=&call;
string=(*ptr)(&a,&b);
printf("%s",string);
return 0;
}
char *call(int *i,float *j){
static char *str="careersadda.com";
str=str+*i+(int)(*j);
return str;
}

A. careersadda.com B. eersadda.com
C. carsadda.com D. ersadda.com

Answer: Option D
Explaination:

Here call is function whose return type is pointer to character and one parameter is pointer to int data type and second parameter is pointer to float data type and ptr is pointer to such function.

str= str+*i+ (int) (*j)
="careersadda.com" + *&a+ (int) (*&b) //i=&a, j=&b
=" careersadda.com' + a+ (int) (b)
=" careersadda.com" +2 + (int) (2.0)
=" careersadda.com" +4
=" ersadda.com"



Discussion

Your Comments Goes here...
NameDiscussion