Search code examples
cioternary-operatorputs

called object is not a function or function pointer in use of ternary


I am constantly receiving:

error: called object is not a function or function pointer

When using ternary operator like that:

puts("\nx: " (0 == 1) ? "y1\n" : "y2\n");


What am I doing wrong?


Solution

  • You are attempting to call an object which is neither a function nor a function pointer! In particular, the compiler is seeing the open paren after the string and thinks (as much as a compiler can be said to "think") that you are trying to invoke a function call. You cannot concatenate a string with the ternary operator as you are trying to do. Try:

    printf("\nx: %s", (0 == 1) ? "y1\n" : "y2\n");