How to install C/C++ in Android using Termux

What is C ?

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations.



How to install C ?

Open Termux app and type following commands

$ pkg install clang
$ pkg install nano

To write your c program type

$ nano filename.c

Hello world program in c :

#include <stdio.h>
int main()
{
   printf("Hello, World!");
   return 0;
}

To compile your c program type

$ gcc filename.c -o aliasname

Example : gcc hello.c -o h

To run your c program type

$ ./aliasname

Example : ./h

How to install C++ ?

Open Termux app and type following commands

$ pkg install clang

OR

$ pkg install g++

$ pkg install nano

To write your c++ program type

$ nano filename.cpp

Hello world program in c++

#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello, World!";
    return 0;
}

To compile your c++ program type

$ g++ filename.cpp -o aliasname

Example : g++ hello.cpp -o h

To run your c++ program type

$ ./aliasname

Example : ./h

You can also compile and run C/C++ code at http://jitcompiler.com

Comments

Post a Comment