Saturday, May 7, 2016

Basics of C Programming - I



Content:-
  1. History,standards,GNU tools
  2. Language Basics,Operators
  3. Control Structures- Decision-making statements, Loops
  4. Pointers and Arrays
  5. Functions
  6. Strings
  7. Structures and Unions
  8. Dynamic Memory
  9. Data Structures-
     Stacks,Queues,Linked List,Trees,Searching and Sorting


The reader is urged to strictly use GCC( GNU C Compiler) for development .

  1. On a Linux machine, Press Ctrl+Alt+T.
  2. The terminal will open.
  3. You can use any of the popular editors like Vi,ViM,emacs,nano, etc.

Let us assume that we are using the Vi editor. To start with a basic C program, follow the below mentioned steps after you have launched the terminal:-
  • vi hello_world.c
  • Press 'i' key. (--INSERT status will be displayed)
  • Now you can type your program here
  • When you are done with your code, press ESC key to come out of input mode.
  • Now press “ :wq “. This will save your program and exit from the editor.
  • Now you are back to the terminal again.
  • Compile the code as :-
        • gcc hello_world.c -o hello_world.out
        • hello_world.out is the executable binary file generated as a result of compilation
  • To execute the binary:-
        • ./hello_world.out


<< If you don't pass any outfile parameter, and just compile the code as:-
gcc hello_world.c
The binary executable file gets generated with the name a.out. You then have to execute it as usual :-
./a.out
>>
<<Linux Shell has a special feature of sentence autocompletion. To leverage it, type partial command and press the TAB key. The entire command will be autocompleted.>>

All the above mentioned steps for writing and compiling a simple C program have been depicted through the following snapshots:-





























For more information on GCC, type the following on the terminal :-
                                
man gcc

 
The whole world of GCC is before you now. Explore as much as possible.

2 comments:

  1. That's very key thing for beginner..Nicely express

    ReplyDelete
    Replies
    1. Thanks. Hope to meet up the same expectations with advanced topics too !!

      Delete