Basics 1
Basics 1
PROGRAMMING
LANGUAGE
(REVISION)
INTRODUCTION
The C language was invented at Bell Labs by
Dennis Ritchie in 1972 to allow the writing of
the UNIX operating system.
CHARACTER SET
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.
int integer1=45;
45
integer1
RULES FOR WRITING
They must begin with a letter.
Length can be of 31 characters, but it should be not
more than 8 characters as first 8 characters are
treated as significant by some compilers.
Uppercase and lowercase are significant. i.e. Total
and total are not same.
It should not be a keyword.
Whitespaces are not allowed.
TOKENS
The smallest individual units of a C- program are
called Tokens. C has six type of tokens.
E.g.
int x, y;
COMMENTS
Comments are added to make a program more
readable to you. Everything that is inside /* and */
is considered a comment and will be ignored by the
compiler. The compiler treats them as though they
were white space or blank characters. You must not
include comments within other comments, so
something like this is not allowed: [*].
/* this is a /* comment */ inside a comment, which is
wrong! */
Comments are a way of inserting remarks and
reminders into a program without affecting its
content.
CONTD..
Comments do not have a fixed place in a program.
Programs can contain any number of comments
without losing speed. This is because comments are
skipped out of a source program by the compiler
when it converts the source program into machine
code.
Comments are marked out or delimited by the
following pairs of characters:
/* ...... comment ......*/ for multiple lines
// for single line
CONSTANT
Constants
Single
Integer Real character
String
constant constant constant constant
AND && =
OR ||
NOT !
Conditional operator is an Comma
equivalent form of if –else
loop. It is called as ternary
operator because used on i = (j=10, j+20);
three operands. This
operator consist of two
symbols: the question mark
(?) and the colon (:).
Syntax:
(Condition) ? statement1 :
statement2
Unary Bi
Minus ~ Bitwise Negation one's
Increment and complement (unary)
Decrement & Bitwise And
| Bitwise Or
Sizeof
^ Bitwise Exclusive Or
Cast >> Right Shift by right hand
side (RHS) (divide by power
of 2)
<< Left Shift by RHS
(multiply by power of 2)
twise
DATA TYPES
TYPE CASTING
When values of different types are mixed in an
expression, they are converted to the same type
before performing the particular operation.
This process of converting values for one type
to another type is known as type conversion.
Real
Integ
er
11. long
double
Charact 10. double
8. unsigned 9. float
er long int
7. long int
6.signed int
5. int
4. unsigned
short
3. short
PROMOTION
Promotion is the process that takes place when
value of an operand of lower rank is assigned to
a variable of type that has a higher rank.
E.g.
int i;
float f;
f=425; //value of f will be 425.0
DEMOTION
Demotion is the process that takes place when a
value of an operand of higher rank is assigned
to a variable of type that has lower rank.
E.g.
int i;
float f;
f=425.76;
i=f; //value of i will be 425
EXPLICIT TYPE CONVERSION
Syntax is:
type(operand) or type(expression)
E.g. (float) x
Will convert variable x of type int to float type.
TYPEDEF
#include<stdio.h>
#include<conio.h>
Void main()
{
typedef int myvar;
myvar val1,val2;
Printf(“Enter 2 values”);
Scanf(“%d%d”,&val1,&val2);
getch();
}
ENUMERATION CASE 1
#include<stdio.h>
#include<conio.h>
Void main()
{
enum day{mon,tue,wed,thu,fri,sat,sun};
printf(“%d”,tue);
}
Output : 1
ENUMERATION CASE 2
#include<stdio.h>
#include<conio.h>
Void main()
{
Enum
day{mon=1,tue,wed,thu,fri,sat,sun};
printf(“%d”,tue);
}
Output : 2
ENUMERATION CASE 3
#include<stdio.h>
#include<conio.h>
Void main()
{
enum
day{mon,tue,wed=7,thu,fri,sat,sun};
printf(“%d”,thu);
}
Output : 8
CONDITIONAL/TERNARY OPERATOR
Syntax:
(Condition) ? statement1 : statement2