Basic of C Language
Basic of C Language
What is 0 and 1
• There are nothing like 0 and 1 in computer there is no
physical significance of 0 and 1
• Any information can be encoded as a sequence of 0 and 1.
Your Data Computer Data
0101010101010101010
ABCD 123 1010101010010100110
010101001010010101
010010010010101010
TEXT +_*()^ 1010100110101100101
010101010011001001
010
What is File ?
File
•File is data bundle Name File
Extension
Track01.mp Dec.jp Raj.txt
3 g
0101010 0101010 0101010
1010101 1010101 1010101
0101010 0101010 0101010
1010101 1010101 1010101
What is Software ?
Application Software Sum.ex
e
System Software 0101010
1010101
0101010
This file is a software
1010101
Program and process
• set of instruction is called program
• Active state of a program is called process
Operating System
• It is a system software
• Example are DOS, Windosxp, Windows Vista, Windows 7,
Windows 8, Solaris, Macintosh, Linux, Ubuntu etc.
• It provides interface between user and machine
• Acts is a manager of the computer system
• It does process management, memory management, File
management etc.
Execution of a program….
Processor
Set of Register
0101010
MU
01010101010101010 1010101
0 0101010
RAM 0101010
1010101
CU Circuit that reads
0101010
1010101
Instructions and
decode it
Programs
Objective
• Constant
• Variable
• Keywords
Constant…
• Any information is called
constant
Data=Information=Constant
Type of Constant
Secondary
Primary Array
Integer String
Pointer
Real Union
Structure
Character
Enumerator
Integer Constant
• -55, 55,
0
Real Constant
•55.6, 24.5, 3.56, -56.0,
2.0
Character Constant
• ‘a’ ‘z’ ‘5’ ‘ ‘ ‘2’
Note:- Character constant valid only one symbol
•‘-3’ ‘3.5’ ‘saurabh’
That is not character constant
because in this constant included
String two or more symbol.
• Sequence of Characters are called String
• “Saurabh” “Mumbai”
Process Memory
Instructions
Program Consumes
Memory in RAM
a
b
Data c
getch();
}
Program gotoxy()
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
gotoxy(40,13);
Printf(“Akash”);
getch();
}
Program of printing variable
The format Specifire can be %d (integer), %c (character),
%s (string), %f (float) %lf(double) etc.
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
main() main()
{ {
int a=5,b=6; int a=5,b=6;
clrscr(); clrscr();
Printf(“a=%d\n”,a); Printf(“sum of %d and
Printf(“b=%d”,b); %d is %d”,a,b,a+b);
getch(); getch();
} }
scanf()
The format Specifier can be %d (integer), %c (character),
%s (string), %f (float) %lf(double) etc.
scanf()
functionfunction is used for input. It reads
The scanf()
the input data from the console.
scanf("format specifier", variable
address);
Program to print cube of given number
#include<stdio.h>
#include<conio.h>
int main(){
int number;
printf("enter a number:");
scanf("%d",&number);
printf("cube of number is:%d ",number*number*numb
er);getch();
}
C Operators
• Arithmetic Operators
• Relational Operators
• Shift Operators
• Logical Operators
• Bitwise Operators
• Ternary or Conditional Operators
• Assignment Operator
• Misc Operator
Precedence of Operators in C
Category Operator Associativity
Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & Right to left
sizeof
Multiplicative */% Left to right
Additive +- Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= Right to left
%=>>= <<= &= ^=
|=
Comma , Left to right
Comments in C
•Single Line Comments
•Multi Line Comments