Suppose a variable pa is always declared as one of two ways:
double * pa
OR
double pa
Can we create an IF statement that does the following
IF (pa is a pointer)
{ pa[0] = 1
}ELSE
{ pa = 1}
EDIT:
Please see How to find out if a pointer array has been filled in C++/C for the follow up question
Not directly, no. Suppose there were a way to do this, something like
What happens if pa isn’t a pointer? You still have that
pa[0] = 1;statement in your program, and it’s illegal, so the compiler is going to reject your program.You might in principle be able to do a compile-time test:
but the power of the C++ preprocessor is very limited; it has no way to test the type of a variable or expression.
If you had this capability, what would you do with it? Tell us what your actual goal is.