Monday 24 June 2013

How to Compile c programme Using gcc


Compiling using gcc



Carry out following steps to compiling through gcc:-

 1)Type the programme using vi editor or Kwrite Editor(for linux users), notepad++(recommended for window users) and save it under the name 'Program1.c'.

 2)At the Terminal(for linux users) & command prompt(for windows user) switch to the directory containig 'args.c' using the cd command.

 for example(for linux users)

 let programming coding is below

gcc compiler
args.c
 now save let us save it on desktop args.c


program name
open the terminal and write the following command
compiling image
it willl tell you about the version of gcc install in your P.C

 root@bt:~# cd /home/Desktop/c_c++                [enter]
 home/Desktop/c_c++#gcc args.c       [enter]
 root@bt:~/Desktop#./a.out program      [enter]

OUTPUT

 Enter the value of a
 56
Value of a=56




Now for windows user:-

 let programming coding is below

 #include<stdio.h>
 int main() 
{
int a; printf("Enter the value of a\n");
 scanf("%d",&a);
 printf("Value of a=%d",a);
 }

now save it as program.c in C:\\Mingw\bin\ and now Open cmd and run the following commands:-

cd C:\mingw\bin      [enter]    (make sure that your program should be in C:\\Mingw\bin\ directory)
gcc program.c         [enter]
a                             [enter]

NOTE: Output in following cases will be created as a.exe(in windows) and ./a (in linux)
if you want output .exe file as program.exe enter the foloowing command

cd C:\mingw\bin                        [enter]    (make sure that your program should be in C:\\Mingw\bin\ directory)
gcc program.c  -o program       [enter]
program                                   [enter]


OUTPUT

 Enter the value of a
56
Value of a=56

follow us on https://www.facebook.com/CreatorOfUniverse

No comments:

Post a Comment