0% found this document useful (0 votes)
38 views

Unit 1

This document provides an overview of the C programming language syllabus including introduction to C, sample programs, integrated development environments, C language elements and program constructs, and C tokens. The main points are: 1) C is a general purpose programming language originally developed in the 1970s and is well-suited for structured programming. It combines high-level and low-level capabilities. 2) A sample C program is presented that uses functions like printf and getch to print and retrieve input. 3) The basic structure of a C program includes sections for documentation, definitions, declarations, the main function, and additional functions. 4) C tokens are the smallest elements like identifiers, keywords, constants

Uploaded by

sneha KP
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)
38 views

Unit 1

This document provides an overview of the C programming language syllabus including introduction to C, sample programs, integrated development environments, C language elements and program constructs, and C tokens. The main points are: 1) C is a general purpose programming language originally developed in the 1970s and is well-suited for structured programming. It combines high-level and low-level capabilities. 2) A sample C program is presented that uses functions like printf and getch to print and retrieve input. 3) The basic structure of a C program includes sections for documentation, definitions, declarations, the main function, and additional functions. 4) C tokens are the smallest elements like identifiers, keywords, constants

Uploaded by

sneha KP
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
You are on page 1/ 7

UNIT I  INTRODUCTION TO C

o C is general purpose, structured programming


SYLLABUS language.
 Introduction to C Programming o Dennis Richie at the Bell Laboratories in
o Overview and Importance of C USA originally developed C in the 1970s.
o C Program Structure o C is the result of the development process that
o Sample programs. started with an older language called
 Familiarization of Integrated Development BCPL(Basic Combined Programming
Environment Language) developed by Martin Richards,
o Invoking IDE and it influenced a language called B, which
o Opening a new window in IDE was invented by Ken Thompson. B led to the
o Writing, Saving and Compiling a C development of C.
program  Importance of C
o Making an Executable File. o Flexibility:
 Elements of C Language and Program  It combines the control structure normally
Constructs: found in High level languages with the
o Character Set ability to manipulate bits, bytes and
o C Tokens addresses, something usually associated
o Keywords with assembly language.
o Identifier  This flexibility allows C to be used for
o Constants system programming as well as for
o Variables application programming.
o Data types o Programs written in C are efficient and fast
o Variable Declaration and Assignment  This is due to its variety of data types and
of Values powerful operators.
o Symbolic Constant Definition. o C is highly portable:
 C program written for one computer can be
run on another with little or no modification.
o C language is well suited for structured
programming:
 User solved a problem in terms of function
modules or blocks.
 This modular structure makes program
debugging, testing and maintenance easier.
o C have the ability to extend itself:
 A C program is basically a collection of
functions that are supported by C library.
 We can continuously add our functions to C
library.
o It is a Robust language:
 Rich set of built in functions and operators
can be used to write any complex program.

GEMS ASC:[email protected]
 Sample Program o Predefined means that it is a function that
o has already been written and compiled, and
#include<stdio.h> linked together with our program at the time
#include<conio.h> of linking.
void main( ) o The printf function causes the everything
{ between the starting and the ending
printf(“WELCOME”); quotation marks to be printed out.
getch( ); o Every statement in C should end with a
} semicolon (;) mark.
 The #include directive
o C programs are divided into modules or
functions. Some functions are written by
users, like us, and many others are stored in
the C library.  Basic Structure of C Program
o Library functions are grouped category-wise
and stored in the library, it is necessary to Documentation section
tell the compiler about the files to be Link Section
accessed. Definition Section
o This is achieved using the pre-processor Global Declaration section
directive #include as follows: main( ) function section
#include<filename> {
Filename is the name of the library file that Declaration part
contains the required function definition Executable part
o Pre-processor directives are placed at the
}
beginning of a program.
 The main( ) function Subprogram section
o The main( ) is a special function used by the Function 1
C system to tell the computer where the Function 2
program starts.
..
o Every program must have exactly one
main() function. Function n
o If we use more than one main() function, the
compiler cannot understand which one Fig: an overview of a C program
marks the beginning of the program.
o The documentation section consists of a set of
o The empty pair of parenthesis immediately
comment lines giving the name of the
follow the main indicates that the function
program, the author and other details, which
main has no arguments(or parameters).
would like to use to later.
o The opening brace marks the beginning of
o The link section provides instructions to the
the function main and the closing brace
compiler to link functions from the system
indicates the end of the function.
library.
o All the statements between these two braces
o The definition section defines all symbolic
form the function body. The function body
constants.
contains a set of instructions to perform the
o There are some variables that are used in
given task.
more than one function. Such variables are
 printf( ) function
called global variables and are declared in the
o printf is a standard C function for printing
global declaration section that is outside of all
output.
the functions.

GEMS ASC:[email protected]
o Every C program must have one main()  C TOKENS
function section. o The smallest individual elements, which are
 This section contains two parts, declaration identified by the compiler, are known as
part and executable part. tokens.
 The declaration part declares all the o Tokens supported in C can be categorized as:
variables used in the executable part.  Identifiers
 There is at least one statement in the  Keywords
executable part.  Constants
 These two parts must appear between the  Special symbols
opening and the closing braces.  Operators
 The program execution begins at the
opening brace and ends at the closing brace.  IDENTIFIERS
 The closing brace of the main function o Identifiers are the names that are given to
section is the logical end of the program. various program elements, such as variables,
 All statements in the declaration and functions, and arrays.
executable parts ends with a semicolon(;). o The rules for forming an identifier are:
o The subprogram section contains all the user-  First character must be an alphabet.
defined functions that are called in the main  Must consist of only letters, digits, or
function. underscore.
 User-defined functions are generally placed  Cannot use a keyword.
immediately after the main function,  Must not contain a white space.
although they may appear in any order.  KEYWORDS
o Keywords are the reserved words that convey
 CHARACTER SET a special meaning to the compiler.
o The characters that can be used to form o All keywords have fixed meanings and these
words, numbers and expressions depend upon meaning cannot be changed.
the computer on which the program is run is o Example:
known as characters set. int double Short
o The characters in C are grouped into long Char Else
following categories: float while If
 Letters
 Digits
 Special characters
 White spaces.
o The compiler ignores white space unless they
are a part of a string constant.
 White spaces may be used to separate
words, but are prohibited between the
characters of keywords and identifiers.

GEMS ASC:[email protected]
 CONSTANTS  These numbers are shown in decimal
o Constants in C refer to fixed values that do notation, having a whole number
not change during the execution of a program. followed by a decimal point and the
o C supports several types of constants: fractional part.
 It is possible to omit digits before the
Constants
decimal point, or digits after the decimal
point.
 Example:
Numeric Character 1.20 .95 215. +.5
Constants Constants  Exponent form
 General from
mantissa e exponent
Integer Real Single String  The mantissa is either a real number
Constants Constants character Constants expressed in decimal notation or an
Constants
integer.
 Integer Constants  The exponent is an integer number with
o Integer constant refers to a sequence of digits. an optional plus or minus sign.
o These are whole numbers without any  The letter e separating the mantissa and
fractional part. the exponent can be written in either
o There are three types of integers: lower case or upper case.
 Decimal integer  Example: 215.65 : 2.1565e2
 It consist of a set of digits, 0 through 9,  Single Character Constants
preceded by an optional – or + sign. o A single character constant contains a single
 Embedded spaces, commas, and non- character enclosed within a pair of single
digit characters are not permitted quote marks.
between digits. o Example:
 Example: „5‟ „X‟ „;‟
Valid: 123 -321 0 +78 o The character constant „5‟ is not the same as
 Octal Integer the number 5.
 It consists of any combination of digits o Character constants have integer values
from the set 0 through 7, with a leading known as ASCII values.
0.  Backslash Character constants
 Hexadecimal Integer o These are used in output functions
 A sequence of digits preceded by 0x or „\n‟ New line
0X is considered as hexadecimal „\t‟ Horizontal tab
integer. „\‟‟ Single quote
„\”‟ Double quote
 They may also include alphabets A
„\\‟ Back slash
through F or a through.
 The letter A through F represent the  String Constants
numbers 10 through 15. o A string constant is a sequence of characters
 Example: 0x2 0x9F enclosed in double quotes.
 Real Constants o The characters may be letters, numbers,
o Real constants are numbers having fractional special characters and blank space.
parts. o Example:
o These may be written in one of the two forms: “Hello” “1987” “5+3”
 Fractional form

GEMS ASC:[email protected]
o A single character string constant does not  DATA TYPES
have an equivalent integer value while a o Data types are means to identify the types of
character constant has an integer value. and associated operations of handling it.
 Special Symbols o C supports three classes of data types:
o Special symbols are mainly used to inform  Primary data types
the compiler, how statements are grouped  Derived data types
together in the code.  User-defined data types
o The following ASCII characters are
separators (punctuators): PRIMARY DATA TYPES
() [] {} ; , . Integral Type

 Operators Integer Character


o Operators specify the evaluation to be Signed unsigned Char
performed on data. int unsigned int Signed char
short int unsigned short int Unsigned char
long int unsigned long int
 VARIABLES
o A variable is a named memory location,
which holds a data value of a particular data
type. Floating point type
o A variable is a data name that may be used to void
float double Long double
store a data value.
o A variable may take different values at
different times during execution.
o All C compiler supports support five
o A variable name can be chosen by the
fundamental data types:
programmer in a meaningful way so as to
 Integer [int]
reflect its function or nature in the program.
 Character[char]
o Variable names may consist of letters, digits
 Floating point[float]
and the underscore character, subject to the
 Double precision floating point [double]
following conditions:
 Void [void]
 They must begin with a letter.
 It is case sensitive. That is the variable
 Integer Types:
Total is not the same as total or TOTAL.
o Integers are whole numbers with a range of
 It should not be a keyword.
values supported by a particular machine.
 Variable Declaration
 Integers occupy one word storage
o All variables must be declared before they
 Since the word size of the machine vary
can appear in executable statements.
(16 or 32 bits) the size of an integer that
o A declaration consists of a data type, followed
can be stored depends on the computer.
by one or more variable names separated by
o In order to provide some control over the
commas and ending with a semicolon.
range of numbers and storage space, C has
o General form:
three classes of integer storage, namely
datatype var_name;
short int, int, and long int, in both signed
o Example:
and unsigned forms.
int a;
 int
char c,a;
 unsigned int
 Assigning values to variables
 short int
o General form
 unsigned short int
var_name=constant;
 long int
data-type var_name=constant;
 unsigned long int
GEMS ASC:[email protected]
o Characters are usually stored in 8 bits(1 bits)
of internal storage.
short int
o The qualifier signed or unsigned may
int explicitly applied to char.
o While unsigned chars have values between 0
long int
and 255, signed chars have values from -128
o We declare long and unsigned integers to to 127.
increase the range of values.
o The use of qualifiers signed integers is Data Type Keyword equivalent
optional because the default declaration Character char
assumes a signed number. Unsigned character unsigned char
 Floating Point Types: Signed character signed char
o Floating point types are used to store numbers Signed integer signed int (or int)
Signed short integer signed short int (short
with fractional parts.
int or short)
o Floating point numbers are defined in C by Signed long integer signed long int
the keyword float. (long int or long)
o Floating point numbers are stored in 32 bits Unsigned integer unsigned int (or
with 6 digits of precision. unsigned)
o When the accuracy provided by a float Unsigned short unsigned short int (
number is not sufficient, the type double can integer or unsigned short)
Unsigned long unsigned long int
be used to define the number.
integer (unsigned long)
 A double data type number uses 64 bits
Floating point float
giving a precision of 14 digits. Double precision double
 These are known as double precision floating point
numbers. Extended double long double
 Double type represents the same data precision floating
type that float represents, but with a point
greater precision.
 To extend the precision further, we may
use long double which uses 80 bits. Type size range
char 8 -128 to 127
unsigned char 8 0 to 255
float int 16 -32768 to 32767
double unsigned int 16 0 to 65535
short int 8 -128 to 127
Long double unsigned short 8 0 to255
Fig: floating point types int
long int 32
 Void Types unsigned long 32
o The void type has no values. int
float 32
o This is usually used to specify the type of
double 64
functions. long double 80
 The type of a function is said to be void
when it does not return any value to the
calling function.
 Character Types
o A single character can be defined as
Character (char) type data.

GEMS ASC:[email protected]
 SYMBOLIC CONSTANT DEFINITION
o A symbolic constant is a name that substitutes
for a sequence of characters. The characters
may represent a numeric constant, a character
constant, or a string.
o Symbolic constants are usually defined at the
beginning of the program.
o General form:
#define identifier text
Where
- identifier represents a symbolic name,
typically written in upper-case letters.
- text represents the sequence of characters
that is associated with the symbolic name.
- the text does not end with semicolon.
o Example:
 #define TAXRATE 0.23
 #define PI 3.141593
 #define FALSE 0
o Advantages:
 Symbolic constants are more readily
identified than the information they
represent.
 It is easier to change the value of single
symbolic constant than to change every
occurrence of some numerical constant
that may appear in several places within
the program.

GEMS ASC:[email protected]

You might also like