i C/C++ development on Linux: Create a first c program – All things in moderation

C/C++ development on Linux: Create a first c program

1.Introduction

This series for someone who want to learn C/C++ programming on Linux specialy for persons want to learn about system programming. I’m going on the way to explore it, so that why I write this series, hope it helfull for all of you !!!
In the first post, I’ll answer serverals question are : C on Linux vs C no Windows, What is the differences ? and what we need to create, build and run a first c program ?

C on Linux and C on Windows, What is the differences ?

The short answer is: the language is the same, but the libraries used to get anything platform-specific done are different. But if you are learing C ( and not systems programming) you should easiy be abel to write porable code.
For examples:
* nonstandard, platform specific includes (<conio.h>, <windows.h>, <unistd.h>, …);
* data type size (the short=16 bit, int=long=32 bit assumption doesn’t hold everywhere);
* undefined behavior (fflush(stdin), as someone else reported, it’s not required to do anything by the standard);

2. Requirements

  • Text editor: if you are a linux users vim is the editor for that. But it’s only for simple program, if’s more complex we need somthings else Visual studio code, Atom,etc.
  • Compiler : GCC it has aready on linux , type “gcc –v” to check version of gcc

  • C standard library

3. Say “I’m happy” with c

Create a file called hello.c using a text editor such as vim, emacs:

#include<stdio.h>  
/* hello.c:  Say hello with c on Linux */  
int main(void)  
{
printf("My first c program on Linux, so happy.\n");  
return 0;

4.Complie and Run

Complie
gcc hello.c -o executable-hello  

-o : ouput file
GCC has many options, but for start we don’t need to know much about it

Run

Type the command:

./hello

Here are result:

Leave a Reply