Running C and C++ applications in Linux is entirely different from Windows TurboC++ users. Linux uses GCC [Gnu Compiler Collections - C and C++ compiler] for developing these applications . Let us see how to develop C and C++ applications in Linux .
Checking GCC compiler
GCC comes with all Linux flavors by default . To check the version of your GCC , type this command in your terminal
By default only C compiler will be there in GCC , you can install C++ support by typing this command in Ubuntu
Developing C Program
You can use your favorite editor or IDE like Netbeans or Eclipse to develop the C and C++ programs. I am using VIM the simple and king of all editor for developing these programs. Now simply we can write one C program for finding factorial of a given number.
#vim factorial.c [ file type is .c ]
Compiling and Running
To compile c program , use gcc with file name
Note :
- There is no void keyword in GCC ,
- Use int instead of void and also use return 0 .
Developing C++ Program
Now I am going to write C++ for the same factorial method.
#vim factorial.cpp [File Type is cpp]
Compiling and Running
To compile c program , use gcc with file name
Note :
- Dont use .h for header files
- Use name space for header-file functions
No comments:
Post a Comment