GCC compiler comes pre-installed on latest Ubuntu.
To check either GCC is installed on your machine or not:
Go to the Terminal by clicking on “Search Your Application Icon” and click on “Terminal” option.
Or
Press : ctrl+alt+t
Now type the below command and press enter.
gcc --version
It will show the gcc version installed on your machine.
If its showing message like "unrecognized command gcc" then gcc compiler is not installed on your machine. Then enter the below command to install gcc compiler on your machine:
$ sudo apt-get install gcc
The above command install gcc compiler on our Ubuntu machine.
Note :
If you are developer then you need to install build-essential for "C" and "C++" for development.
Just run the below command in your terminal to install build-essential:
$ sudo apt-get install build-essential
Now again check the Version of the gcc by typing “gcc --version” command it will show as:
Steps to Create First c program.
1. Create a c file with ".c" extension "MyFirstProgram.c"
2. Write the below program in "MyFirstProgram.c" file
#include <stdio.h>
void main()
{
printf("Hello this is My First C Program..!\n");
}
3. Save it.
4. Now open terminal and go to the "MyFirstProgram.c" file location by "cd" command.
5. Now type below command to compile your "C" program:
gcc MyFirstProgram.c -o MyFirstProgramOut
Here "-o MyFirstProgramOut" stores output i.e. compile code (Machine readable code) of the "MyFirstProgram.c" file after compilation.
6. Now write below command to execute the the program
./MyFirstProgramOut
7 Now check your output:
To check either GCC is installed on your machine or not:
Go to the Terminal by clicking on “Search Your Application Icon” and click on “Terminal” option.
Or
Press : ctrl+alt+t
Now type the below command and press enter.
gcc --version
It will show the gcc version installed on your machine.
If its showing message like "unrecognized command gcc" then gcc compiler is not installed on your machine. Then enter the below command to install gcc compiler on your machine:
$ sudo apt-get install gcc
The above command install gcc compiler on our Ubuntu machine.
Note :
If you are developer then you need to install build-essential for "C" and "C++" for development.
Just run the below command in your terminal to install build-essential:
$ sudo apt-get install build-essential
Now again check the Version of the gcc by typing “gcc --version” command it will show as:
Now write and execute your 1st C program:
Steps to Create First c program.
1. Create a c file with ".c" extension "MyFirstProgram.c"
2. Write the below program in "MyFirstProgram.c" file
#include <stdio.h>
void main()
{
printf("Hello this is My First C Program..!\n");
}
3. Save it.
4. Now open terminal and go to the "MyFirstProgram.c" file location by "cd" command.
5. Now type below command to compile your "C" program:
gcc MyFirstProgram.c -o MyFirstProgramOut
Here "-o MyFirstProgramOut" stores output i.e. compile code (Machine readable code) of the "MyFirstProgram.c" file after compilation.
6. Now write below command to execute the the program
./MyFirstProgramOut
7 Now check your output:
No comments:
Post a Comment