Here is a simple C++ code named test.cpp to detect whether a pointer is null.

using namespace std;
int main()
    int *a;
        cout<<"a points at something."<<endl;
        cout<<"a is a null pointer."<<endl;
    return 0;

I compiled it in two devices:

  1. Termux in Redmi-K20-Pro Android phone (unrooted) with clang: clang++ test.cpp -o op
  2. gnome-terminal in Raspberry-Pi-4B with gcc: g++ test.cpp -o op

Then I ran the program with ./op but the results were different:

  1. Termux printed a points at something
  2. gnome-terminal printed a is a null pointer.

Obviously the second result is right.

Because both devices are based on ARMv8 architecture, so no hardware problem exists. There must be some problems with Termux, the compiler, the Android system root, or something else.

Is there any solution to fix this immediately?

  • Even if you use the Android app termux your problem is a C++ programming question which is totally unrelated to Android, and hence off-topic here. Most likely it is caused by different C++ compilers.
    – Robert
    Commented Sep 23, 2020 at 8:40
  • Assuming we're blind about the code since this site focuses on Android end-users who are not necessarily developers (Stack Overflow is for programming issue), how about compiling with GCC in Termux?
    – Andrew T.
    Commented Sep 23, 2020 at 15:02


You must log in to answer this question.

Browse other questions tagged .