0% found this document useful (0 votes)
4 views32 pages

Overview of C Programming Language

The document provides a comprehensive overview of the C programming language, including its structure, compilation process, evolution, and characteristics. It discusses C tokens, keywords, identifiers, constants, data types, and variables, highlighting the rules for naming and declaring them. Additionally, it emphasizes C's significance in system programming and its foundational role in modern programming languages.

Uploaded by

nnm24ee089
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views32 pages

Overview of C Programming Language

The document provides a comprehensive overview of the C programming language, including its structure, compilation process, evolution, and characteristics. It discusses C tokens, keywords, identifiers, constants, data types, and variables, highlighting the rules for naming and declaring them. Additionally, it emphasizes C's significance in system programming and its foundational role in modern programming languages.

Uploaded by

nnm24ee089
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Contents

1. Structure of a C Program
2. C Compilation Model
3. Evolution & Characteristics of C Language
4. Characters set
5. C tokens(Keywords, identifiers Constants, Variables, Data Types and
Declaration of Variables)
Introduction:
● C is a general purpose language which is very closely associated with
UNIX for which it was developed in Bell Laboratories.
● Most of the programs of UNIX are written and run with the help of 'C'.
● Many of the important ideas of 'c' stem are from BCPL by Martin
Richards.
● In 1972, Dennies Ritchie at Bell Laboratories wrote C Language which
caused a revolution in computing world .
● From beginning C was intended to be useful for busy programmers to
get things done easily because C is powerful,dominant and supple
language.
ALGOL 1960-First Computer language to use block structure ( Algorithmic
Language)
| BCPL 1967- Martin Richards

B 1970- Ken Thompson

C 1972- Dennis Ritche

K & RC 1978- Kerninghan & D Ritchie

ANSI C 1989- American National standard institute

ANSI/ ISO C C99 1999


Dept. of CSE, NMAMIT, Nitte. 3
1990
Basic structure of C program:
Structure of C program is defined by set of rules called protocol, to be followed by
programmer while writing C program. All C programs are having sections/parts
which are mentioned below.
1. Documentation section
2. Link Section

3. Definition Section

4. Global declaration section

5. Function prototype declaration section

6. Main function

7. User defined function definition section


5
Compilation Process:
• Starting with source code (e.g. C) and converting it into
machine code that the computer can run.
• When using our IDE, the process appears like this:
Compilation:
● compiler translates source program into equivalent target
program, then goes away
● often high-level language (source code) translated to
machine language (object code)
● OS later executes target program on machine
● better performance
● The compilation is a process of converting the
source code into object code or machine code.
• The compiler checks the source code for the
syntactical or structural errors, and if the source code
is error-free, then it generates the object code.
• The compilation process can be divided into four
steps, i.e., Pre- processing, Compiling, Assembling,
and Linking.
● A source code is written in alphanumeric form which is the
computer cannot understand.
● It must be converted into binary form or machine language.
● The process of translating a high-level language program into
machine language is called compilation.
● When compilation is completed, a new file is created in C called
OBJ file or object file.
● Its file extension is .obj and is created by the compiler
Evolution & Characteristics of C
Language
● C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System
(OS) in the early 1970s.
● C provides a variety of data types.
● In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of the C
Programming Language by Kernighan & Ritchie caused a revolution in the
computing world. Origin of C
● Evolved from two previous languages – BCPL, B
● BCPL (Basic Combined programming language) used for writing OS & compilers B
used for creating early versions of UNIX OS
● Both are “typeless” language
● C language evolved from B (Dennis Ritchie – Bell labes)
● C is a high-level and general purpose programming language that is ideal for developing
firmware or portable applications.
● C is what is called a compiled language.
● Today C is the most widely used System Programming Language.
● Most of the state of the art software have been implemented using C
● Why C?
● C was initially used for system development work, in particular the programs that make-up
the operating system.
● C was adopted as a system development language because it produces code that runs
nearly as fast as code written in assembly language.
● Some examples of the use of C might be: • Operating Systems • Language Compilers •
Network Drivers • Modern Programs • Data Bases • Utilities
● C is a structured programming language C supports
functions that enables easy maintainability of code, by
breaking large file into smaller modules.
● Comments in C provides easy readability.
● C is a powerful language.
● One can say, C is a base for the programming.
● If you know ‘C,’ you can easily grasp the knowledge of the
other programming languages that uses the concept of ‘C’
● C supports functions that enables easy maintainability of
code, by breaking large file into smaller modules
● C programs built from :- • Variables and type declarations •
Functions • Statements • Expressions
● C Programming Language • Variables • Flow control •
Statement • Expressions • Operators • Functions • C
compiler • Output
● Characteristics of C Language

● ‘C’ is a general purpose programming language.


● ‘C’ is a structured programming language.
● ‘C' is Top Down Approach
● ‘C’ is highly portable.
● ‘C’ has rich set of built-in-functions and operators
● ‘C’ supports various data types
● ‘C’ has keywords
● ‘C’ is case sensitive, for example num is different from NUM.
● ‘C’ supports pointers and operations on pointers.
C is considered a procedure-oriented programming language (POP). This
means it focuses on procedures or routines (functions) to operate on data,
organizing code around functions and procedures. Key characteristics of
procedure-oriented languages include:
[Link] Programming: Code is divided into small modules or functions,
which can be reused.
[Link]-down Approach: The design starts from the top, specifying complex
operations first, and breaking them down into smaller operations.
[Link] Data: Data can be shared among functions.
[Link] Structures: Use of loops, conditionals, and other control structures to
dictate the flow of the program.
C TOKENS:
C tokens are the smallest individual units of a C-program. These are
the basic buildings blocks in C language which are constructed together to
write a C program. Each and every smallest individual units in a C program are
known as C tokens.
C tokens are of six types. They are:
1. Keywords (eg: int, while)
2. Identifiers (eg: main, total)
3. Constants (eg: 10, 20)
4. Strings (eg: “total”, “hello”)
5. Special symbols (eg: (), {})
6. Operators (eg: +, /,-,*) 18
C TOKENS EXAMPLE PROGRAM:
int main()
{
int x, y, total;
x = 10, y = 20;
total = x + y;
printf ("Total = %d \n", total);
}
where,
✔ main – identifier
✔ {,}, (,) – delimiter
✔ int – keyword
✔ x, y, total – identifier
✔ main, {, }, (, ), int, x, y, total – tokens

Dept. of CSE, NMAMIT, Nitte. 19


KEYWORDS IN C LANGUAGE:
•Keywords are pre-defined words in a C compiler.
•Each keyword is meant to perform a specific function in a C program.
•Since keywords are referred names for compiler, they can’t be used as variable name.
•C language supports 32 keywords.
Examples are
auto double case enum
int struct register typedef
const float default goto
short unsigned sizeof volatile
break else char extern
long switch return union
continue for do if
20
signed void static while
IDENTIFIERS IN C LANGUAGE:
Identifiers are the names provided to the elements of a program such as variables, functions
and arrays are examples for identifiers.
eg. x is a name given to integer variable in above program.

RULES FOR CONSTRUCTING IDENTIFIER NAME IN C:

•First character should be an alphabet or underscore.


•Succeeding characters might be digits or letter.
•Punctuation, spaces and special characters aren’t allowed except underscore.
•Identifiers should not be keywords.
•Identifiers are case sensitive.
•Ex: valid identifiers: salary, num, _sum, int_num, avg_salary, num6
•Invalid : int, 9num, n@um
Dept. of CSE, NMAMIT, Nitte. 21
C – Constants
•C Constants are also like normal variables. But, only difference is, their values can not be
modified by the program once they are defined.
•Constant is a fixed value assigned to a variable which cannot be modified in a program. They
are also called as literals.
•Constants may be belonging to any of the data type.
Syntax: const data_type variable_name;
Ex: const int a=3.14; const char letter= ‘n’ ;

22
TYPES OF C CONSTANT:
I. Integer constants : These constant must have digits without decimal point and it be either
negative or positive.
II. Real or Floating point constants : These constant must have digits along with the decimal
point and it be either negative or positive.

III. Octal & Hexadecimal constants: These are the numerical constants which start with 0 and 0x
respectively.
IV. Character constants : These constants are a single alphabet, single digit or single special
symbol enclosed within single quotes.
V. String constants : These constants are a single or several alphabet(s), single or several digit(s)
or single or several special symbols or combination of these enclosed within double quotes.
VI. Backslash character constants : C provides backslash constants which perform specific
actions. Ex: ‘\n’ newline, ‘\t’ tab space, ‘\0’ null character etc.
Constant type data type (Example)
int (53, 762, -478 etc )
unsigned int (5000u, 1000U etc)
Integer constants
long int, long long int
(483,647 2,147,483,680)

float (10.456789)
Real or Floating point constants
doule (600.123456789)

Octal constant int (Example: 013 /*starts with 0 */)

Hexadecimal constant int (Example: 0x90 /*starts with 0x*/)

character constants char (Example: ‘A’, ‘B’, ‘C’)

string constants char (Example: “ABCD”, “Hai”)


24
DATA TYPES IN C
• A data type in programming is a classification that specifies which type of value a
variable can hold and how the data is stored and manipulated within a program.
Data types define the operations that can be performed on the data, the meaning of
the data, and the way values of that type can be stored.
• In C, data types are essential as they determine how much memory is allocated for
a variable and what kind of operations can be performed on that variable.
The Four fundamental data types:
‘C’ supports four basic data types:

Data type Keyword Size (in bytes)


Integer int 2
Real (Floating point) float 4
Double precision real double 8
Character char 1

Dept. of CSE, NMAMIT, Nitte. 26


Data type modifiers:

The storage size in bytes and range of values being represented by basic data
types can be modified with the help of the following modifiers or qualifiers as
prefixes.

[Link]
[Link]
[Link]
[Link]

Dept. of CSE, NMAMIT, Nitte. 27


Modifier Size (Bytes) Range of values
int 2 −32768 to +32767
signed int 2 −32768 to +32767
unsigned int 2 0 to 65535
short int 2 −32768 to +32767
long int 4 −2147483648 to +2147483647
unsigned short int 2 0 to 65535
unsigned long int 4 0 to 4294967295
char 1 −128 to +127
signed char 1 −128 to +127
unsigned char 1 0 to 255
float 4 −3.4E+48 to +3.4E+48
double 8 −1.7E+308 to +1.7E+308
long double 16 −3.4E−4932 to +1.1E+4932

For range of values : where n= no. of bits


-2n-1 to 2n-1 – 1 for signed values
0 to 2n for unsigned values 28
What is a Variable?
• A variable is an identifier which is used to store some value. Variables are the named storage location that
holds a data.
• Constants can never change at the time of execution.
• Variables can change during the execution of a program and update the value stored inside it.
• When you declare a constant or a variable, the compiler reserves a memory location in which to store the
value of the constant or variable.

RULES FOR NAMING C VARIABLE:

•First character must be letter or underscore, and then it can have considerable number of digits, letter,
underscore.
•Keywords cannot be used as identifiers.
•Variables are case sensitive
•No special symbols are allowed other than underscore.
•sum, height, _value are some examples for variable name
29
Following are the examples of valid variable names in a 'C'
program:
➢height or HEIGHT
➢ _height
➢_height1
➢My_name

invalid variable names in a 'C' program:

➢1height
➢ Hei$ght
➢my name

Dept. of CSE, NMAMIT, Nitte. 30


DECLARING & INITIALIZING C VARIABLE:

•Variables should be declared in the C program before to use.


•Memory space is not allocated for a variable while declaration. It happens only on variable
definition.
•Variable initialization means assigning a value to the variable.

Type Syntax
data_type variable_name;
Variable declaration
Example: int x, y, z; char flat, ch;

data_type variable_name = value;


Variable initialization
Example: int x = 50, y = 30; char flag = ‘x’, ch=’l’;
31
Symbolic Constants:

•‘C’ allows defining a variable name as having a constant value using a pre
processor directive #define
•Such pre processor statements are placed at the beginning of the program and are
not a part of the C program.
•Such statements begin with the # symbol and hence do not end with a semicolon.
A symbolic constant can be used to define a numeric constant or a character/string
constant.
Once defined, a symbolic constant’s value can be used at many places in the
program.
The syntax of symbolic constant is:

#define symbolic_name value of constant


#define PI 3.141
#define CLASS “H Section”
Dept. of CSE, NMAMIT, Nitte. 32

You might also like