You are on page 1of 3

Introduction to ‘C’ Programming

C language combines the power of a low-level language and a high-level language. The low-
level languages are used for system programming, while the high-level languages are used for
application programming. It is because such languages are flexible and easy to use. Hence, C
language is a widely used computer language.

It supports various operators, constructors, data structures, and loop constructs. The features of C
programming make it possible to use the language for system programming, development of
interpreters, compilers, operating systems, graphics, general utilities, etc. C is also used to write
other applications, such as databases, compilers, word processors, and spreadsheets.

Structure of the C Program


The basic structure of a C program is divided into some parts which makes it easy to read, modify,
document, and understand in a particular format. C program must follow the below-mentioned
outline in order to successfully compile and execute. Debugging is easier in a well-structured C
program.
Sections of the C Program
There are some basic sections responsible for the proper execution of a program. Sections are
mentioned below:

1. Preprocessor Section
2. Definition
3. Global Declaration
4. Main() Function

 Preprocessor Section
All the header files of the program will be declared in the preprocessor section of the program.
Header files help us to access other‟s improved code into our code. A copy of these multiple files
is inserted into our program before the process of compilation.

Example:

#include<stdio.h>
#include<conio.h>
#include<math.h>

 Definition
Preprocessors are the programs that process our source code before the process of compilation.
There are multiple steps which are involved in the writing and execution of the program.
Preprocessor directives start with the „#‟ symbol. The #define preprocessor is used to create a
constant throughout the program. Whenever this name is encountered by the compiler, it is
replaced by the actual piece of defined code.
Example:
#define pi=3.14

Global Declaration

The global declaration section contains global variables, function declaration, and static variables.
Variables and functions which are declared in this scope can be used anywhere in the
program. Example:

int num = 18;


Main() Function

Every C program must have a main function. The main() function of the program is written in this
section. Operations like declaration and execution are performed inside the curly braces of the
main program. The return type of the main() function can be int as well as void too. void() main
tells the compiler that the program will not return any value. The int main() tells the compiler that
the program will return an integer value.
Example:
void main()
or
int main()

What is a Character set?


Like every other language, „C‟ also has its own character set. A program is a set of instructions
that, when executed, generate an output. The data that is processed by a program consists of
various characters and symbols. The output generated is also a combination of characters and
symbols.

A character set in „C‟ is divided into,

 Letters

 Numbers

 Special characters

1) Letters

 Uppercase characters (A-Z)

 Lowercase characters (a-z)

2) Numbers

 All the digits from 0 to 9


Special characters

 Special characters in ‘C’ are shown in the given table,


Tokens in C

Tokens are the smallest elements of a program, which are meaningful to the compiler.
The following are the types of tokens: Keywords, Identifiers, Constant, Strings, Operators, etc.

Keywords

Keywords are predefined, reserved words in C and each of which is associated with specific
features. These words help us to use the functionality of C language. They have special meaning
to the compilers.

There are total 32 keywords in C.

auto double int struct

break else long switch

case enum register typedef

char extern return union

continue for signed void

do if static while

default goto sizeof volatile

const float short unsigned

Identifiers

Each program element in C programming is known as an identifier. They are used for naming of
variables, functions, array etc. These are user-defined names which consist of alphabets, number,
underscore „_‟. Identifier‟s name should not be same or same as keywords. Keywords are not used
as identifiers.

Rules for naming C identifiers −

 It must begin with alphabets or underscore.


 Only alphabets, numbers, underscore can be used, no other special characters, punctuations
are allowed.
 It must not contain white-space.
 It should not be a keyword.

Strings

A string is an array of characters ended with a null character(\0). This null character indicates that
string has ended. Strings are always enclosed with double quotes(“ “). Let us see how to declare
String in C language −
 char string[20] = {„h‟,‟e‟,‟l‟,‟l‟,‟o‟, „\0‟};
 char string[20] = “diploma”;
 char string [] = “diploma”;

You might also like