Sei sulla pagina 1di 6

Chapter: - 1 Basics Concepts:-

Introduction and History:-


Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention
was to develop a language for writing an operating system (OS). As you know an OS is software which controls
the various processes in a computer system. This language was later improved by Ken Thompson and he gave it
a new name B. The basic ideas about some topics such as arrays, etc., which were later inherited by C were
developed in BCPL and B. In those days, the development of computers was in infancy. One of the serious
constraints experienced while developing the language B was the small computer memory available at that
time.
C is a general purpose computer programming language developed in 1972 by Dennis Ritchie at
the Bell Telephone Laboratories for use with the Unix operating system. It was named 'C' because many of its
features were derived from an earlier language called 'B'.
Many of the ideas of structure of C language were taken from BCPL and B. Ritchie has given an excellent
exposition of the problems experienced during development of C in his lecture entitled "The Development of the
C Language".
Although C was designed for implementing system software, it is also widely used for developing
portable application software.
The earlier C was also called B with types though many ideas were also borrowed from ALGOL 68. A
second phase of developments in C came in during the years 1977-1979. C became popular because of the
success of UNIX system which was largely written in C and which could be used on different types of computers.
C is a structured high-level language. Programs written in C are easy to write and debug as well as portable.
The programs written in C are quite efficient. However, the code written in C language needs a compiler to
convert different instructions and data into machine language.
C is one of the most popular programming languages of all time and there are very few
computer architectures for which say C compiler does not exist. C has greatly influenced many other popular
programming languages, most notably C++, which began as an extension to C.
C is an imperative (procedural) systems implementation language. It was designed to be compiled using
a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs
that map efficiently to machine instructions, and to require minimal run-time support. C was therefore useful for
many applications that had formerly been coded in assembly language.
C's design is tied to its intended use as a portable systems implementation language. It provides simple,
direct access to any addressable object (for example, memory-mapped device control registers), and its source-
code expressions can be translated in a straightforward manner to primitive machine operations in the
executable code.

Characteristics:-
Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and
allows lexical variable scope and recursion, while a static type system prevents many unintended operations. In
C, all executable code is contained within functions. Function parameters are always passed by value. Pass-by-
reference is simulated in C by explicitly passing pointer values.
Heterogeneous aggregate data types (struct) allows related data elements to be combined and manipulated as
a unit. C program source text is free-format, using the semicolon as a statement terminator.
C also exhibits the following more specific characteristics:
Variables may be hidden in nested blocks partially weak typing. For instance, characters can be used as
integers. Low-level access to computer memory by converting machine addresses to typed pointers Function
and data pointers supporting ad hoc run-time polymorphism array indexing as a secondary notion, defined in
terms of pointer arithmetic.
A preprocessor for macro definition, source code file inclusion, and conditional compilation Complex
functionality such as I/O, string manipulation, and mathematical functions consistently delegated to library
routines A relatively small set of reserved keywords A large number of compound operators, such as +=, -=,
*=, ++ etc.
Character Set Consists Of
Whenever we write any C program then it consists of different statements. Each C Program is set of
statements and each statement is set of different c programming lexims. In C Programming each and every
character is considered as single lexim. i.e [Basic Lexical Element]

Types Character Set


Lowercase Letters a-z
Types Character Set
Uppercase Letters A to Z
Digits 0-9
Special Characters !@#$%^&*
White Spaces Tab Or New line Or Space
Valid C Characters: Special Characters are listed below

Symbol Meaning
~ Tilde
! Exclamation mark
# Number sign
$ Dollar sign
% Percent sign
^ Caret
& Ampersand
* Asterisk
( Left parenthesis
) Right parenthesis
_ Underscore
+ Plus sign
| Vertical bar
\ Backslash
` Apostrophe
Minus sign
= Equal to sign
{ Left brace
} Right brace
[ Left bracket
] Right bracket
: Colon
Quotation mark
; Semicolon
< Opening angle bracket
> Closing angle bracket
? Question mark
, Comma
. Period
/ Slash

C Tokens Chart
In C Programming punctuation, individual words, characters etc. are called tokens.
Tokens are basic building blocks of C Programming

Token Example:
No Token Type Example 1 Example 2
1 Keyword do while
2 Constants number sum
3 Identifier -76 89
4 String HTF PRIT
5 Special Symbol * @
6 Operators ++ /
Basic Building Blocks and Definition:
Token Meaning
A variable is a meaningful name of data storage location in computer memory. When using a
Keyword
variable you refer to memory address of computer
Constant Constants are expressions with a fixed value
Identifier The term identifier is usually used for variable names
String Sequence of characters
Special
Symbols other than the Alphabets and Digits and white-spaces
Symbol
Operators A symbol that represent a specific mathematical or non-mathematical action

Keywords in C Programming Language :


1. Keywords are those words whose meaning is already defined by Compiler
2. Cannot be used as Variable Name
3. There are 32 Keywords in C
4. C Keywords are also called as Reserved words.
32 Keywords in C Programming Language
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Variable:-
Variable in C Programming is also called as container to store the data. Variable name may have different
data types to identify the type of value stored. Suppose we declare variable of type integer then it can store
only integer values. Variable is considered as one of the building block of C Programming which is also called as
identifier.
A Variable is a name given to the memory location where the actual data is stored.
Consider real time example, suppose we need to store water then we can store water in glass if quantity of
water is small and Bucket is the quantity of water is large. And big can to store water having quantity larger
than bucket similarly Variable (i.e. Value container) may have different size for storing different verities of
values.
1. Variable Name always holds a single Value.
2. Variable Name is user defined name given to Memory Address.
3. During Second Run , Address of Variable may change.
4. During second Run , Value set inside variable during current will be considered as garbage..
Defining Variable:-
Syntax:-
Datatype Variable Name;

Rules For Constructing Variable Name


1. Characters Allowed :
o Underscore(_)
o Capital Letters ( A Z )
o Small Letters ( a z )
o Digits ( 0 9 )
2. Blanks & Commas are not allowed
3. No Special Symbols other than underscore(_) are allowed
4. First Character should be alphabet or Underscore
5. Variable name Should not be Reserved Word.
What is Declaration ?
To declare is nothing but to represent a variable.
Only Variable name and its Data type is Represented in Declaration.
Facts about Declaration:
1. Memory is neither allocated to Variable nor space is Reserved after declaration.
2. Declaration is just used for Identification of Data Type.
3. Re-Declaration of variable will cause compile Error.
int ivar;
int ivar = 10;

It will cause compile error. We cannot re-declare variable.


4. We cannot use variable inside program expression or in program statements without declaring.
5. Declaring a variable just give rough idea to compiler that there is something which is of type <Data
Type Specified> and will be used in the program.

Example Of Declaration :
int ivar;
float fvar;
char cvar;

Operators in C Language:-
Arithmetic Operator in C Programming Language
1. C Programming Supports 5 Arithmetic Operators.
2. Arithmetic Operators are used for Arithmetic Calculation.
Supported Arithmetic Operators:
5 arithmetic operators are shown in the following table. Arithmetic operators are used to perform
arithmetic operations in c programming.
Operator Meaning Example
+ Addition Operator 10 + 20 = 30
- Subtraction Operator 20 10 = 10
* Multiplication Operator 20 * 10 = 200
/ Division Operator 20 / 10 = 2
% Modulo Operator 20 % 6 = 2

Relational Operator in C Programming


Relational operators in c programming is used for specifying the relation between two operands such as
greater than, less than and equals.
In C Programming we can compare the value stored between two variables and depending on the result
we can follow different blocks using Relational Operator in C.
In C we have different relational operators such as
Operator Meaning
> Greater than
>= Greater than or equal to
<= Less than or equal to
< Less than

Assignment Operator in C Programming Language:


1. Assignment Operator is used to assign value to an variable.
2. Assignment Operator is denoted by equal to sign
3. Assignment Operator is binary operator which operates on two operands.
4. Assignment Operator has Two Values L-Value and Value. Operator copies R-
Value into L-Value.
5. Assignment Operator has lower precedence than all available operators but has
higher precedence than comma Operator.

Logical Operator in C Programming


Whenever we use if statement then we can use relational operator which tells us the result of the
comparison, so if we want to compare more than one conditions then we need to use logical operators. Suppose
we need to execute certain block of code if and only if two conditions are satisfied then we can use Logical
Operator in C Programming.
Operator Name of the Operator
&& And Operator
|| Or Operator
! Not Operator

In C Programming , Unary operators are having higher priority than the other operators. Unary Operators are
executed before the execution of the other operators. Increment and Decrement are the examples of the Unary
operator in C.

Increment Operator in C Programming


1. Increment operator is used to increment the current value of variable by adding integer 1.
2. Increment operator can be applied to only variables.
3. Increment operator is denoted by ++.
Different Types of Increment Operation
In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment Operator.
A. Pre Increment Operator
Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-
Increment value is first incremented and then used inside the expression.
b = ++y;
In this example suppose the value of variable y is 5 then value of variable b will be 6 because the value of y
gets modified before using it in a expression.
B. Post Increment Operator
Post-increment operator is used to increment the value of variable as soon as after executing expression
completely in which post increment is used. In the Post-Increment value is first used in a expression and then
incremented.
b = x++;
In this example suppose the value of variable x is 5 then value of variable b will be 5 because old value of x
is used.
Sample program
#include<stdio.h>

void main()
{
int a,b,x=10,y=10;

a = x++;
b = ++y;

printf("Value of a : %d",a);
printf("Value of b : %d",b);
}
Output :
Value of a : 10
Value of b : 11

We have seen increment operator in C Programming which increments the value of the variable by 1. Similarly
C Supports one more unary operator i.e decrement operator which behaves like increment operator but only
difference is that it decreases the value of variable by 1.

Decrement Operator in C Programming :


1. Decrement operator is used to decrease the current value of variable by subtracting integer 1.
2. Like Increment operator, decrement operator can be applied to only variables.
3. Decrement operator is denoted by .
Different Types of Decrement Operation :
When decrement operator used in C Programming then it can be used as pre-decrement or post-decrement
operator.
A. Pre Decrement Operator
Pre-decrement operator is used to decrement the value of variable before using in the expression. In the Pre-
decrement value is first decremented and then used inside the expression.
b = --var;
Suppose the value of variable var is 10 then we can say that value of variable var is firstly decremented then
updated value will be used in the expression.
B. Post Decrement Operator
Post-decrement operator is used to decrement the value of variable immediatly after executing expression
completely in which post decrement is used. In the Post-decrement old value is first used in a expression and
then old value will be decrement by 1.
b = var--;
Value of variable var is 5. Same value will be used in expression and after execution of expression new value
will be 4.
C Program
#include<stdio.h>

void main()
{
int a,b,x=10,y=10;

a = x--;
b = --y;

printf("Value of a : %d",a);
printf("Value of b : %d",b);

}
Output :
Value of a : 10
Value of b : 9

Conditional Operators [ ?: ] : Ternary Operator Statement in C


1. They are also called as Ternary Operator .
2. They also called as ?: operator
3. Ternary Operators takes on 3 Arguments
Syntax :
expression 1 ? expression 2 : expression 3
where
expression1 is Condition
expression2 is Statement Followed if Condition is True
expression2 is Statement Followed if Condition is False

Potrebbero piacerti anche