+ 5

What is wrong in this code

int check(int i,int j) { int *p,*q; p=&i; q=&j; i>=45 ?return *p : return *q ; }

21st Nov 2016, 10:28 AM
Tarun Sharma
Tarun Sharma - avatar
5 Answers
+ 12
You are not suppose to return in conditional statement. Maybe you can try like this return i>=45? *p : *q; Also why you are doing like this? simply do like return i>=45? i: j; and remove those 2 pointers
21st Nov 2016, 10:44 AM
Venkatesh(Venki)
Venkatesh(Venki) - avatar
+ 3
but why please elaborate it.
23rd Nov 2016, 5:30 PM
Tarun Sharma
Tarun Sharma - avatar
+ 2
u are writing return in conditional operator it is wrong
10th Jan 2017, 8:43 AM
Shivam Upadhyay
Shivam Upadhyay - avatar
0
antarastriya beijatti baap ko sikhayega
29th Nov 2016, 3:55 AM
Tarun Sharma
Tarun Sharma - avatar
0
the last line has no meaning. you should use if statements or inline conditionals. here's the code for inline conditional. (replace the last line with the following) : return ((i >= 45) ? *p : *q) ;
28th Jan 2017, 10:39 PM
Megziflips