Structure of  C Program

Include header file section
Global declaration section
/*      comments      */             
main () //function name              
{                  
        Declaration part
        Executable part              
}
User defined functions 
{
    Declaration part
    Executable part              
}

Include header file section

Ex: #include <stdio.h>

Global declaration

Function main()

Declaration part

Executable part

User-defined function

Comments

Various steps in C program execution

  1. Editing
  2. Compiling
  3. Linking
  4. Execution

Editing

Compiling

Linking

Execution

Characteristics of ‘C’

Generality

Middle-level language

Extensive library functions

Efficiency and speed

Portability

Structured programming

The First C program

void main() 
{
   printf(“WELCOME TO BALUTUTORIAL”); 
}

Above program will print WELCOME TO BALUTUTORIAL on screen

Leaning C is similar and easier. Instead of straight-away learning how to write programs, we must know keywords, operators, separators, constants, predefine functions and syntax of C language.

What is Token?

Keywords

Ex: while, if, else, case, break, etc.

auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

Character set

Letters Capital A to ZSmall a to z
Digits All decimal digits 0 to 9
White spaces Blank space, horizontal tab, vertical tab,New line, form feed
Special characters ,  . ;  : ‘ “  ! | / \  ~ _ $ ? &  ^ * – + < >  ()  [] {}  % # = @

Delimiters(Separators)

Delimiters Use
: colon Useful for label
; semi colon Terminates statement
() parenthesis Used in expression and function.
[] square bracket Used for array declaration
{} curly brace Scope of statement
# hash Pre-processor directive
, comma Variable separator

Constants

Numeric constants
  1. Integer constants: Ex: 10, +30, -15 etc.
  2. Real constants: Ex: 2.5, 5.521, 3.14 etc.
Character constants
  1. Single character constants:  Ex: ‘a’, ‘8’, ‘ ’ etc. (Alpha numeric)
  2. String constants: Ex: "Hello", "444", "a" etc.

Identifiers

Variables

Input/Output’s

Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. When a program needs data, it takes the data through the input functions and sends results obtained through the output functions. Thus, the input/output functions are the link between the user and the terminal. The I/O functions are classified into two types:

Formatted functions

The formatted I/O functions read and write all types of data values. They require conversion symbol to identify the data type. Hence, they can be used for both reading and writing of all data values.

The formatted functions return the values after execution. The return value is equal to a number of variables successfully read/written. Using this value the user can find out the errors occurring during reading or writing the data.

Ex:printf(), scanf();

Unformatted functions

The unformatted I/O only works with the character data type. They do not require conversion symbol for identification of data types because they work only with a character data type.

There is no need to convert the data. In case the values of other data types are passed to these functions, they are treated as the character data. The unformatted functions also return values, but the return value of an unformatted function is always the same.

Types: