Plant propagation: Sexual and Asexual propapagation.pptx
What is c
1. What is c?
Do you tell us about c, perhaps you thing that
is a programming language but……
now……….
What is z?
You tell us it is an alphabets. In the same way
c is also an alphabets.
Now when some one asking you about c
language then tell him about c language.
This type of answer make an impression on
interviewer, which is beneficial for us.
2. History of c language –
algol
(kenthomsan) B BCPL (Mortin)
c (Denice Richi)
(At & t bell laboratory in U.S.A.)
3. C language developed in 1972 at & t bell
laboratory in U.S.A.
First time c language written in Unix, but in
further it written in it self.
Unix O.S. is also written in c language.
4. Basic element of c languages.
Every language have some elements which help
us to understand and working with that language.
So there are some element in c also …..
Alphabets -
a, b………?
A, B………z.
Numeric values – 0,1,2………9.
Special symbols –
# , ; : ( ) [ ] { } / * + - %...............
Key words –
There are 32 keywords in c language.
5.
6. Some predefine function in c
print f ( )
scan f ( )
getch ( )
clrscr ( )
getche ( )
7. printf – it is a predefine function which is use
to print something on the screen at runtime.
printf (“Namaste”);
In above example what we write down in
double quarts that is printed same an screen.
int x;
x = 10;
printf (“ % d “, x);
In ex printf print the value of x.
8. scanf – it is also a predefine function
which is use to take user input at runtime
(execution time)
int x;
scanf (“ % d”, f x)
In above example we take value for x
variable integer type.
9. getch ( ) – It is also predefine function
which hold the screen, till it dose not get a
character.
As it get the character it release the
screen.
getche( ) – getche ( ) is also work same
as getch ( ), but difference it first print the
taken character then release the screen.
10. Inclucle <stdio.h>
vaid maine ( )
{
Print f (“vandematram”);
Getche ( );
Getch ( );
}
Hear first getche ( ) hold the screen, when he
get a character then it release, then getch()
hold;
11. # include <stdio.h>
void main ( )
{
Print f (“vandematram”);
getch ( );
getche ( );
}
Hear first getch ( ) hold the screen, when
he get a character then it release, then
getche() hold;
12. Identifiers – Identifiers are such type of entity
through which we uniquely identified any thing.
ex- variable name, painter name, array name,
function name, structure name, union name etc.
Rule for identifiers name –
An identifier contain only alphabets, numeric
values and under score (-).
An identifiers name always start with alphabets or
under score.
No special symbols or white space use instead of
under score. (-).
13. Variable – variable are those identifiers
which value change during the program.
ex –
int x;
char y;
Constant – constant are those identifiers
which value never change during in
program.
14. Data type – it tell us about the type of are
identifiers.
ex -
int a;
In above ex- a is an integer type variable, it
hold the integer value the key word int tell
s us.
15. Type of data type – There are manly two
type of data type in c.
Primary data type.
Secondary data type.
Primary data type secondary data type
int string
float array
char painter
double structure
union
function
16. int– int is a key word which is used to
create a integer type variable.
ex –
int x
x = 10;
x hold integer type value.
17. char – It is also a key word which is used
to create a character type variable it
always hold a single character, which is
denoted by „ ‟ (single a uates)
char a;
a =„m‟;
In above a is a character type variable
which hold a single character.
18. float – it is also a key word which is used
to create a float type variable.
ex-
float b;
b = 2.35;
In above, b is a float type variable hold a
decimal value.
19. Operators in c-
C support a number of built-in operators. we have already
used several of them,
Some are =,+,-,*,&and <.An operator is a symbol that tells the
computer to perform some manipulation to manipulate data
and variables.
C operators can be classified in to a
i) number of categories.
ii) relational operators.
iii) logical operators.
iv) assignment operators.
v) increment & decrement operators
vi) arithmetic operators
vii) conditional operators
viii) bitwise operators
ix) special operators.
20. Arithmetic operators-
C provides all the basic arithmetic operators.
They are listed in table.
Operators Meaning
+ Addition or unary plus
- Subtraction or unary minus
* Multiplication
/ Division
% Modulo division
21. ex-1.
int a, b, c;
b = 10;
c = 12;
ex- 2. a + b + c;
float b = 2.5;
c = 3.2;
a = b + c;
ex-3.
int a;
float b, c;
a = 10;
c = 3.5
b = a + b;
22. Relation operators-
We often compare two quantities and
depending on their relation. Take certain
decisions. For this type of comparisons we
use relation operators.
those are- Operator Meaning
< is less than
<= is less than or equal to
> is greater than
<= is greater than or equal
to
== is equal to
23. Logical operators-
In addition to the relational
operators. C has
these following logical operators.
Operator Meaning
&& logical AND
|| logical OR
! logical NOT
Assignment operators-
Assignment operators are used to assign an
opropriate value to the variable.
We use „=‟ as assignment operator.
24. Increment and decrement operators-
C allows two very use full operators these
are increment and decrement operators.
++ and --
*The operators ++ adds 1 to the operand,
while – subtracts 1. * both are unary
operators and (such operators which work
with single operand (variable).
ex- int a;
a + +;
25. They are implemented in two ways
Prefix.
Pastfis.
Prefix- first perform in crement decrement
then assigne the value.
int a;
++ a;
int b;
-- b;
Postfix – first assigne the the value then
perferm increment decrement.
26. Conditional operator-
There is an operator pair “?” is available in C,
to construct conditional expressions of the
form.
A1 ? A2 : A3
A1, A2, A3 are expressions .
in above first expressions A, evaluated.
a = 10;
b = 15;
m = (a > b) ? a : b;
It is use to replace if use.
28. If ……. else
This is a bi-direction conditional control statement. This
statement is used to test a condition and take one of the two
possible actions.
If the condition is true then a single statement or block is
executed, other wish another single statement or block is
executed.
if (condition)
{
Statement 1
}
Else
{
Statement 2
}
29. Nesting of if ……. else-
We can have another if….. else statement
in the if block or the else block if….. else
statement.
30. Switch –
This is a multi-directional conditional control statement some time there is a
need in program to make choice among number of alter natives.
For making this choice, we use the switch statement.
switch (expression)
{
case 1:
statement 1;
Break; ………..
case 2:
statement 2;
… Break; ………
case 3:
statement 3;
…… Break; ……
default :
statement 4;
………..
}
31. Now we will see the same valid invalid ways of writing switch
expression and case expression.
int a, b, c; char d, e; float f;
Valid –
Switch (a) switch (a>b) switch (d+e-3) switch (a>b && b>c)
switch cfine (a,b,)
Invalid –
switch (f) switch (a+4.5)
Valid case 4: case „a‟ : case 2+4
case „a‟ > „b‟ :
Invalid –
case ”second” : case 2.3 : case a :
case a>b : case a+2 :
case 2, 3, 4 : case 2 : 4 : 3 :
32. Loop - loops are used when we want to execute a part of program or a
block of statement several times.
There are three loop statement in C-
for loop
while loop
do while loop
for – the for loop is very usefull in C programming.
It has three expressions and semicolons are used for separating these
expression.
for (initialization; condition; increment)
{
statement;
}
ex-
int a;
for (a=0; a<3; a++)
{
printf (“Namuste”);
}
33. While –
It is written as –
initialization;
while (condition)
{
statement :
Increment /Decrement;
}
ex- int a;
a=0;
while (a<3)
{
printf (“ Vande Matram”);
a ++;
}
34. do while – it is different from for and while loop. it first execute the
statement then check the condition.
initialization :
do
{
statement :
increment /Decrenet)
}
while 9condition);
ex-
int a;
a = 0;
do
{
printf (“ jai Hanuman”);
a ++;
}
while (a < 5);
* in do while condition is either true or false statement must executed once.
35. Nested loop-
When we use a loop inside the another loop body
(both are same) it is known as nested loop.
ex-
for (x = 0 ; x < 5 ; x + +)
{
for (y = 1 ; y < 5 : y + +)
{
printf (“% d % d ‟‟ x, y) ;
}
}
In above this the example of nested for loop.
36. Function – function is an entity which perform
some specific.
A function is a self-contained subprogram that is
meant to do some specific, well-define task.
*A program consists of one or more function.
*If a program has only one function then it must be
the main ( ) function .
*function always return a value.
C program have two types of function –
1. Library function
2. User define function
37. Library function –
C has the facility to provide library functions for
performing some operations. These function are present
in the C library and they are predefined.
Function Name Operation
Sgrt ( ) find squre root of nuber
scanf ( ) take input
printf ( ) for print on screen
strlen ( ) lenth of string
strcmp ( ) comparision
clrscr ( ) for clear the screen
getch ( ) for hold the screen
38. User- define function-
User can create their own functions for performing any specific
task of the program. These type of function are called user
define function.
User define function have these three parts-
1. Function declaration
2. Function definition
3. Function calling
Function definition-
The function definition consist of the whole description and
code of a function. It tells what the function is doing and what
are its input and output.
Function calling-
A function is called by simply writing its name followed by the
argument list inside the parentheses (if any).
39. Function declaration-
Function declaration give the information to calling function
about called function.
If called function is placed before calling function then there no
need for declaration.
ex- #includi <stdioh>
valid ram ( ) ; declaration
valid main ( ) ; of function
{
ram ( ) ; calling offention
}
Void ram ( )
{
printf (“ vande matram ‟‟) ;
}
40. Type of user define function –
1. function with no argument and no return type.
2. function with no argument and a return type.
3. function with argument and no return type.
4. function with argument and a return type.
Function with no argument and no return type-
A function which has no argument and no return type………..
#include<stdio.h>
void func ( ) ;
void main ( )
{
func ( ) ;
}
void func ( )
{
statement ;
}
In above program func ( ) has no argument and it does not return any value.
41. Function with no argument and a return type –
These type of function do not recene any argument but return
a value.
int func ( ) ;
void main ( )
{
int n ;
n = func ( ) ;
}
int func ( )
{
int a ;
………
………
return a ;
}
42. function with argument and no return type.-These types of
function have arguments, hence calling function send data to
the calling function but function does not return a value.
void func (int a) ;
void main ( )
{
int m ;
func (m);
}
void func (int x)
{
……………….
……………….
……………….
}
43. Function with argument and a return type-
These type function have arguments, so the calling function can send data
to the called function. It can also return any value to the calling function
using return statement.
int func (int, int)
{
void main ( )
{
int r ;
…….
r = func (a, b) ;
……….
}
int func (int a, int b)
{
………….
………….
return (expression) ;
}
44. Arrays –
The variables that we have used till now are capable of storing
only one value at a time.
So we have an array that can hold more than one value of
some type.
“ Array is a collection of similar type of data.‟‟
ex -
int a [10] ;
a [10] = {1, 2, 5, 3, 2…...} ;
In above example a is an array of size 10, it can hold 10
values of same time of data type.
ex-2- int a [3] 0, c‟ ;
for (c‟ = 0 ; c‟ < 3 ; c‟ ++)
{
scanf (“ % d‟‟, & a [c‟] ) ;
}
45. ex-1- int a [3] ;
a [0] = 10 ;
a [1] = 22 ;
a [2] = 11 ;
/* The size of array is 3, it hold three value */
Print the value of an array –
int a [3] 0, c‟ ;
for ( I = 0 ; c‟ < 3 ; c‟ ++ )
{
printf ( “ % d”, a [i] ) ;
46. Passing array to a function –
We know that an array element is treated as any other simple variable in the
program. So we can simply pass an individual array element to the function
as argument.
void funct ( int a ) ;
void main ( )
{
int arr [10], i ;
for ( i = 0 ; c‟ < 10 ; c‟ ++ )
{
scanf ( “ % d‟‟, & arr [i] ) ;
funct ( arr [i] ) ;
}
void funct ( int num )
{
……………
……………
…………..
…………..
}
47. 2- D Array –
The syntax of 2-d array is similar to 1-d array, but here we
have two subscripts.
Data type array- name [ row size ] [ Colum size ] ;
Here row sixe specifies number rows and colum size specifies
number of calumn.
Reading value in 2-d Array –
int a [2] [2] 0, c‟, j ;
for ( c‟ = 0 ; c‟ < 2 ; c‟ ++ )
{
for ( j = 0 ; j < 2 ; j ++ )
{
scanf ( “ % d‟‟, & a [i] [ j ] ) ;
}
}
48. Displaying values of array –
int a [2] [2] 0, c‟, j ;
for (c‟ = 0 ; c‟ < 2 ; c‟ ++ )
{
for ( j = 0 ; j < 2 ; j ++ )
{
printf ( “ % d‟‟, a [i] [ j ] ) ;
}
}
49. Introduction to string –
In C string are treated as array of char type and are
terminated by a rull character („0‟)
There are the two forms of initialization of a string variable –
char str [10] = {„I‟, „n‟ , „d‟ , „I‟ , „a‟ , „10‟ } ;
char str [10] = “ India „‟ ;
In second case rull character automatically placed in the end
of string.
Input of output of string –
# include < stdio‟h >
void main ( )
{
char str [10] ;
scanf (“ % s ”, str) ;
printf (“ % s ‟‟, str) ;
}
50. Pointer –
Pointer is an identier which hold the address
of any variable which data type is similar to
pointer.
ex-
int x = 10 ;
int * p ;
P = & x ;
In above example p is a pointer which hold
the address of x variable.
51. Example to understand the painte ?
# include < stdio.h>
void main ( )
{
int a, * b ;
a = 10 ;
b=&a;
printf (“ % d % d % d % d‟‟ , a, &a, b, * b);
}
Output –
value a - 10
address of a ………
address of a ………
value of a - 10
52. Pointer to pointer –
A pointer may be hold the address of
another pointer.
int *a, **b, c‟ ;
c‟ = 10 ;
a = & c‟ ;
b = & a ;
In above case a hold the address of c‟
variable and double pointer b (**) hold the
address of a.
53. Increment decrement in pointer –
Pointer variable also perform increment /
decrement operation ;
int a, * b ;
a=5;
b=&a;
b ++ ;
printf (“ % d ‟‟, b) ;
In above example pointer increase two by test be
couse increment perform in the address of
variable.
We can also perform arithmatic operation in
pointer.
54. Pointer and function –
The argument to the function can be passed in two ways –
1. call by value.
2. call by reference.
In call by value, only values of argument send to the function.
But in call by reference address of argument send to the
function.
Structure –
Array is a collection of same type of elements, but in real word
application we may need to group different types of logically
related data.
So for that we use structure.
“ structure is a collection of different type of corelated data.
55. Syntax –
struct tag name
{
data type member 1;
data type member 2;
………………..
……………..
data type member x ;
};
Here struct is a keyword.
ex- struct student
{
char name [20] ;
int age ;
}
void main ( ) {
Struct student 51 ;
51. name = “ arpit ‟‟ ;
51. age ;
printf ( “ % s % d ‟‟, 51. name, 51. age) ; }
56. Union –
Union is a derived data type like structure, and it can also contain
members of different data types.
It‟s declaration and accessing of member element is same to
structure only one different in it, use keyword union instead of struct.
Union union-name
{
data type member 1 ;
data type member 2 ;
…………………
};
main ( )
}
Union union-name x ;
………………..
……………….
}