C and C++ Compiler for Android: 3 Ways to Run C Code
To compile and run C or C++ on an Android phone, use an app that ships a compiler: Pocket Compiler: Run Code compiles C and C++ on the phone with Pro (a one-time download, then it works offline), Cxxdroid is a dedicated C/C++ IDE, and Termux lets you install clang from the command line. All three run the program on the device; none need root.
Which one fits you
| App | C/C++ on the device | Other languages | Interface | Cost |
|---|---|---|---|---|
| Pocket Compiler: Run Code | Yes (one-time download, then offline) | Python, JavaScript, React, HTML, SQL, Java, PHP | Editor with Run button, program input, errors that point to the line | Free to download; some features are part of an optional upgrade |
| Cxxdroid | Yes | C and C++ focus | C/C++ IDE | Free with ads; premium available |
| Termux | Yes, after pkg install clang |
Anything you install | Command line | Free, open source |
If you only write C and C++, a dedicated IDE like Cxxdroid is a reasonable pick. If you also write Python, Java or SQL for class, one app that runs all of them saves switching. If you want make, many files and a real shell, Termux is the most flexible.
What Pocket Compiler does for C and C++
- Compiles and runs on the phone. Tap ▶ Run and see the output, or the compiler error with the line it came from. Tap the error to jump there.
- Program input:
scanfandcinwork. Type the input, then run. - Offline after one download. The C/C++ toolchain is a one-time download (internet needed once).
- A program stuck in a loop stops at the time limit, so the app stays usable.
- Java is free, if your course also uses Java.
What it does not do
- C and C++ are Pro features, and they are Android only. The iPhone app runs Python, JavaScript, HTML and SQL.
- Runs stop at 20 seconds with Pro, so it is for exercises and small programs, not long simulations.
- It is not a full build system. For
makeand large multi-file projects, Termux is better suited.
Steps: run a C program on Android
- Install Pocket Compiler: Run Code.
- Create
main.cand type:
#include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
printf("sum = %d\n", a + b);
printf("7 / 2 = %d\n", 7 / 2);
return 0;
}
- Tap ▶ Run. The first time, the app offers the C/C++ download (Pro).
- Type
3 4in the input box and run. You getsum = 7and7 / 2 = 3, because integer division drops the remainder. - For C++, create
main.cppand usecinandcoutthe same way.
Steps: the Termux way
- Install Termux (its maintainers recommend F-Droid or GitHub builds).
- Run
pkg install clang. - Write
main.cwith a terminal editor such asnano. - Compile with
clang main.c -o mainand run./main.
Frequently Asked Questions
Can I run C++ on Android without internet?
Yes. Pocket Compiler needs internet once to download the C/C++ toolchain, then it runs offline. Termux also works offline once clang is installed.
Is there a free C compiler for Android?
Termux with clang is free. Cxxdroid has a free version with ads. In Pocket Compiler, C and C++ are Pro; Python, JavaScript, HTML, SQL and Java are free.
Does scanf work in a phone compiler?
In Pocket Compiler, yes: type the input before you run.
Can I compile C on iPhone?
Not in Pocket Compiler: C and C++ are Android only.
Do I need root?
No.
More about the app, including screenshots and the full free-vs-Pro list, is on the Pocket Compiler page.