INTRODUCTION TO PROGRAMMING
INTRODUCTION
The C programming language is a structure oriented programming language,
developed at Bell Laboratories in 1972 by Dennis Ritchie.
C programming language features were derived from an earlier language called
“B” (Basic Combined Programming Language – BCPL)
C language was invented for implementing UNIX operating system.
In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C
Programming Language” and is commonly known as K&R C.
In 1983, the American National Standards Institute (ANSI) established a
committee to provide a modern, comprehensive definition of C. The resulting
definition, the ANSI standard, or “ANSI C”, was completed late 1988.
Many of C’s ideas & principles were derived from the earlier language B,
thereby naming this new language “C”.
CHARECTERESTICS OF A C PROGRAM
• Small size- it has only 32 keywords
• Extensive use of functional cal
• It is a structured language
• Supports loose typing- a character can be treated as an integer and vice
versa.
• It can be compiled into a variety of computers
Applications
The C programming language is used for developing system applications that
forms a major portion of operating systems such as Windows, UNIX and Linux.
Below are some examples of C being used:
Database systems
Graphics packages
Word processors
Spreadsheets
Operating system development
Compilers and Assemblers
Network drivers
Interpreters
WHAT IS THE STRUCTURE OF A C PROGRAM ?
Documentations (Documentation Section)
• Pre-processor Statements (Link Section)
• Global Declarations (Definition Section)
• The main() function
o Local Declarations
o Program Statements & Expressions
• User Defined Functions
C TOKENS
In a C Program, the smallest individual units are known as C -Tokens. Programs
are written using these tokens and syntax of language. There are totally six
tokens. They are:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
Keywords: are those words, whose meaning is already known to the C
compiler i.e. they are predefined words. The keywords cannot be used as
variable names.
There are only 32 keywords available in C.
Identifiers: They refer to the names of variable, functions and arrays. These
are user-defined names and consist of a sequence of letters and digits, with
a letter as a first character. Both uppercase and lowercase letters are
permitted, although lowercase letters are commonly used. The underscore
character is also permitted in identifiers.
Constants: Constants in ‘C’ refer to fixed values that do not change during
the execution of a program. Constant is a memory location in which a value
can be stored and this cannot be altered during the execution of program.
‘C’ supports several types of constants. They are illustrated below.
Error in C language
ERROR
Syntax error: Some statements in the program is not a legal statement in the
language.
Runtime error: An error occurs while the program is executing, causing the
program to terminate(divide by zero, etc.)
Logical error: The program executes to completion, but gives incorrect results.
EXAMPLE OF A BASIC PROGRAM :
BASIC STRUCTURE:
o #include <stdio.h>
o void main()
o {
o int a;
o printf( "Please enter a number: " );
o scanf( "%d", &a );
o printf( "You entered %d", a );
o return 0;
o }
EXAMPLE:
Question: C Program to find sum of two numbers
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the value of A = ");
scanf("%i",&a);
printf("enter the value of B = ");
scanf("%i",&b);
c=a+b;
printf("The sum is = %i",c);
return 0;
}