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

Lecture 2 Programming Language C

The document provides an overview of programming languages, specifically focusing on the C programming language. It explains the structure of programming languages, character sets, escape sequences, tokens, keywords, identifiers, and delimiters. Key concepts such as global and local variables, along with rules for defining identifiers, are also discussed.

Uploaded by

islamrafiul046
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 2 Programming Language C

The document provides an overview of programming languages, specifically focusing on the C programming language. It explains the structure of programming languages, character sets, escape sequences, tokens, keywords, identifiers, and delimiters. Key concepts such as global and local variables, along with rules for defining identifiers, are also discussed.

Uploaded by

islamrafiul046
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Programming Language C

Language
v Language: A language is a structured system for communication.
v Natural Language: A structured system for communication between two
or more human beings. For example, Bangla, English, etc.
v Programming Language: A structured system of writing programs for
either (i) communication between two or more machines; or (ii) human
machine interaction.

Constituents of Language
Natural Language Programming Language
Letter Character
Alphabet Character Set
Word Token
Sentence Statement
Essay Program
Character Set
v Computer can store or recognize only 0 and 1. Letter or character like A, B can
be stored or recognized by a computer. Hence, the characters are
represented by some numbers, known as codes. For example, ‘A’ is
represented by 65, ‘a’ is represented by 97, ‘0’ is represented by 48 and so
on.
v In America, 128 characters are coded with the numbers ranges from 0 to 127,
which are known as ASCII (American standard code for information
interchange). Another 128 characters are coded with the numbers ranges
from 128 to 255, which are known as extended ASCII. All of these 256
characters are supported by C programming. 8 bits or 1 byte memory is used
to represent an ASCII Character.
v Later on, all the symbols used in worldwide languages are coded using 16 bits
or 2 bytes, which is known as UniCode (Universal codes). A Maximum of
65536 characters can be coded using Unicode. C programming does not
support Unicode.
v Each character is represented within single quotes like ‘A’, ‘B’, ‘0’ and so on.
Escape Sequence
v There are some unprintable characters, which are followed by a backslash (\)
and performs some specific tasks, are known as escape sequence.
v Some escape sequence with their details are given below:
Escape Sequence Character ASCII Code
\0 NULL Character 0
\a Bell 7
\b Backspace 8
\t Horizontal Tab 9
\v Vertical Tab 11
\n Newline 10
\r Carriage return 13
\’’ Quotation Mark 34
\’ Apostrophe 39
\? Question 63
\\ Backslash 92
Token
Classification of Tokens
Token

Keyword/ Identifier Delimiters/ Operators Functions


Reserved Punctuations
Word

Variable Constant

Unary Binary Ternary


Operator Operator Operator

Assignment Arithmetic Logical Relational


Operator Operator Operator Operator
Keyword/Reserved Word
v Keyword: mandatory words to learn a language.
v Reserved word: words whose meaning or purpose is fixed and cannot be
used for any other purposes.
v In any programming language, keywords and reserved words are the same
set of words.
v Programming language is easy to learn because of few reserved/key words.

Some reserved/key words in C programming


include define main if
for do while switch
case break continue int
long char float double
void auto extern static
const default else goto
return short signed unsigned
Sizeof struct union typedef
Identifier
v Identifier: Identifier is a name given to a specific memory location.
Identifier
Identifiers are of two types:
ü Variable
ü Constant Variable Constant

v Variable: when the content of an identified memory location is allowed to


be changed, then the identifier is called variable. Variables are defined as
follows: int A, B;
char ch;
v Constant: Content of memory location cannot be changed. Constants are
defined using macros, like
#define pi 3.14159
Identifier
Some Rules of defining Identifiers:
Ø Must be started with a letter or underscore (_).
Ø No space, delimiter or operator is allowed within an identifier.
Ø Should not be reserved/key word.

Different types of Identifiers:


Ø char
Ø Integer (short, int, long, signed,
unsigned)
Ø Floating points (float, double)
Scope of Identifier
Classification of variable/Identifier based on scope:

Identifier

Global Local

v Global Variable: A variable declared before the main() function


is called global variable. This variable can be accessed from
every function of the program.
v Local Variable: A variable declared within any function can be
accessed from that function only. This variable cannot be
accessed from any other function. This type of variable is called
local variable.
Scope of Identifier
#include <stdio.h>
void add(int x, int y);
int sum;

void main(){
int x = 5, y = 7;

add(x, y);
printf(“The sum is %d.”, sum);
}
void add(int p, int q){
sum = p + q;
}
Delimiters/Punctuations
vDelimiter: A delimiter is a sequence of one or more characters
that specifies the boundary or acts as a separator.

Common delimiters used in C programming are-


ü comma (,)
ü Semicolon (;)
ü Quotation (“)
ü Apostrophe (‘)
ü Parentheses (), Braces {} and Brackets []
ü Forward slash (/), backslash (\)

You might also like