2. Table of Contents
Overview…………………………………………………………2
Basic structure of program…………………… ………………4
Data type………………………………………… ………………8
Variable & Constants……………………………………………12
Decision Making & Branching ……………………………… 16
The loop………………………………………………………… 25
The Array………………………………………………………… 33
The Function………………………………………………………38
The Recursion…………………………………………………… 42
The pointer…………………………………………………………43
The String………………………………………………………… 47
The structure……………………………………………………… 49
Overview
C language
C is a general-purpose, high-level language that was originally
developed by
Dennis M. Ritchie to develop the UNIX operating system at Bell
Labs. C was
originally first implemented on the DEC PDP-11 computer in
1972.
3. In 1978, Brian Kernighan and Dennis Ritchie produced the first
publicly available
description of C, now known as the K&R standard.
The UNIX operating system, the C compiler, and essentially all
UNIX application
programs have been written in C. C has now become a widely
used professional
language for various reasons:
Easy to learn
Structured language
It produces efficient programs
It can handle low-level activities
It can be compiled on a variety of computer platforms
Facts about C
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around the
early
1970s.
The language was formalized in 1988 by the American National
Standard
Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System
Programming
Language.
Most of the state-of-the-art software have been implemented
using C.
Today's most popular Linux OS and RDBMS MySQL have been
written in
C.
Why Use C?
2
4. C was initially used for system development work, particularly the
programs that
make-up the operating system. C was adopted as a system
development
language because it produces code that runs nearly as fast as the code
written
in assembly language. Some examples of the use of C might be:
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
Chapter 1
Basic structure of Program
C Programs
A C program can vary from 3 lines to millions of lines and it should be
written into one or more text files with extension ".c"; for example,
hello.c. You can use "vi", "vim" or any other text editor to write your C
program into a file.
This tutorial assumes that you know how to edit a text file and how to
write source code inside a program file
3
5. C language:
C language is language of computer. The maker of c language is
Dennis Richie in 1972 at bill lab.in using c language bill gate make
operating system, android operating system also make android apps
etc.
C language also known as basic language of computer
Now we discussed history of c language
History of C language
DennisRichiearemaker of C languagein 1972in billlab
Basic Structure of C language
Basicstructure is using structuring of programming where we discussed
aboutsection
Example:
documentation section, sub section and predefined etc.
We discussed one by one
There are 7 basics structuring section of programming.
1: Documentation section
The documentation sectionwhere we explained why we written
Example:
int main(int x,int y); //decelerated function//
*/------------/* used for locking / unlocked statements
4
6. 2: Link section
The link section is also known as library. library is predefined section
where we linked program to library.
Example
#include<stdio.h> //library section //
3: Defining section
The user defined in link sectionto all area using where it’s calling
Example:
#define max 50
4: Global Declaration section
A function/variable whichdeclared outside of body of programming in
globally
5: local declaration section
A function/variable which declared inside of body of programming is
Known as local declaration section
6: Main()
Main () is type of function where are declared/execute the statement.
Example:
Main ()
{
Printf(“sabeel bugti”);
//declaration
Scanf(“%d”); //Executable
5
7. }
7: Sub program section
The user defined function are declared area.
Main()
{
Function 1-----
Function 2-----
Function n--- //declared user defined function//
} First programming of C language
This is first programming in c language where we print “sabeel bugti”.
Basic Explain part of C language
# is the preprocessor and also known starting part of programming
Clrscr() is used for previous record.
Getch() is used of holding output during executables.
Printf() is used for outputting massage/statement.
Scanf() is used for reading statement/output massage.
6
8. “Sabeel Bugti” quotation is used as showing massage/statement.
Compiler: program first compile the program statement. When we code
are error in the compiler are dedicate by giving msg.
Execute: when our code corrects by checked by compiler. The executer
are execute the statement.
Save: save programming in massage.c etc.
Syntax: is a grammar/method of programming is call syntax.
There are three type of Error.
1: syntax (grammatical error).
2: Logical (un requirement output error).
3: Retune ( repeating error).
Chapter 2
DATA TYPE
Data .
Data is a set of values of subjects with respect
to qualitative or quantitative variables.
Example:
A,b,1,8,5 these things known as data
7
9. Data type.
A data type determines the type and the operations that
can be performed on the data. C++ provides various data
types and each data type is represented differently within
the computer's memory.
Classified of Basic Data Types in C+
There are many data-types available in C+
They are classified under two categories:
Built-In or Fundamental Data types
Derived or User-Defined Data types
8
10. Built-in Data Type
Built-indata types are the most basic data-types in C++.
The term built-in means that they are pre-defined in C++ andcan be
used directly in a program.
Example:
• Character char
• Integer int
• Floating point float
• Double floating point double
Apart from these, we also have void and bool data types.
Derived Datatype
They are composed of built-in data types.
Examples are :
array, structure, union, class, pointers etc.
User Define Data Type
User-defined data types are those which are first
declared and defined by the user before use.
Example:
struct ; union ; class; enumeration; are User defined types
9
11. Explain Data Type in C
Char: Characters refer to the alphabet, numbers and other characters
(such as {, @, #, etc.) defined in the ASCII character set.
Int: Numbers without the fractional part represent integer data. In C++,
the int datatype is used to store integers such as 4, 42, 5233, -32, -745.
Floating point Data Type: A floating-point data type is used to store real
numbers suchas 3 .28, 64. 755765, 8.01, -24.53.
Void: The void data type is used for specifying an empty parameter list
unction and return type for a function.
Bool : The boo1data type can hold only Boolean values, that is; either
true or false, where true represents 1 and false represents 0.
Array :
An array is a set of elements of the same data type thatare referred to
by the same name.
Function:
A function is a self-contained program segment thatcarries out a
pacific well-defined task.
Reference:
A reference is an alternative name for a variable. Thatis, a reference is
an alias for a variable in a program.
Knowing
10
12. Chapter 3
Variable and Constant in C
Variable def.
The variable is during programming in changed by changed
execution are known as variable
Syntax. Data type, variable name, ; semi colon.
Example. Int a;
Constant def.
11
13. The constant is value are constant in programming. It’s do not change
during execution.
syntax. Data type variable name = value and semi colon.
Example. Int a=100;
Operators
Operatordef.
Operator arealsoknown symbols(+,%,^,*,=).It’sis used in programin easily
understandablestatement.
Operators withuses.
Thegraphwhich show usesnameand example.
Assigning value to variable
Theprocessor methodwherewegiving valueto variable.Themethodknown as
assigningvalueto variable.
Syntax: return typevariablename= value;
12
14. Example int subject = 100;
Program to find asci value of a character in c
language.
The program which show value (in which already exit in library) of
character.
After the find value of keyboard key we find all key operators after this
programming.
Now we make program which show all operators and keyword ascii.
Let’s start program.
The program of ascii find all value of keyboard.
13
15. This program are all value of keyword which predefined in library.
Output of all asci program.
All code of ascii here which already declared in library. The value of these
thing.
Your assignment.
Your assignment is asci of “happy birthday”.
Note.
14
16. In turbo c++ sometime don’t executed.
Be practice because computer is practical. You get new thing
practice againand again.
Chapter 4
Decision making andbranching program
the program which bases of condition are make is called
decision making andbranching
there are 4 branching statement
1: if statement
2: switch statement
3: conditional operators statement
4: go to statement
(1) if statement
1: simple if
15
17. 2: if...else
3: nested of if base
4: Else if ladder
1: Simple if
syntax
if(condition)
{
statement;
}
Using this syntax, we make even number program.
Even number program using simple statement.
16
18. What is flowchart?
The flowchart is graphic representation of programming.
What is Algorithm?
The algorithm is step by step written / explain process is called
Algorithm.
Simple statement program algorithm.
*start the program to main ().
*get variable i.
*print mag “enter a number”.
*scan used the msg.
*used simple statement to putting condition.
*condition true then print number is even
*end of program.
2: If statement…. else.
17
19. The if statement and else are used more thansimple condition. We
used else.
Now we make program which after checking number is odd or even.
Let’s start the program.
Syntax: if(condition)
{ Statement;
}
Else
{statement;
}
Using syntax to make program even or odd.
The program which checked all condition than true value are printed.
Program flowchart.
18
20. The Algorithm of program.
*start the program to main().
*get integer variable no.
*print massage and read by scanf.
*used condition (if/else).
* compiler check true condition and printed true condition.
*end the program.
3: Nested if statement.
An if statement which statementinside another statement is known as
20
21. Nested if statement.
4: Else if ladder statement
the if else ladder are method of stair known wich we make pargram
stair/ladder.
Syntax. If(condition1)
{
Block1
}
Else If (condition 2)
{
Block 2
}
Else if (condition)
21
22. {
Block 3
}
Else
{
Block 4
}
Now we make calculator using of if else ladder statement.
So let’s start the program.
.
The calculator makes in if else ladder statement. Now if statement
process is completed.
22
23. Now switch statement.
3: Conditional operator statement
Conditional operator (? true) or (: false).the operator are decided which
is true and false.
Syntax. (condition)? expression1:expression2.
23
24. 4: go to statement.
Go to statement which start again and again using by the go to
statement.
24
25. Chapter 5
The Loop
Loop Def.
The repeating sequence of sentence/statement is called loop.
Flowchart of loop
There are five type of loop.
1: The While loop
2: The Do while loop
3: The for loop
4: The Nested loop
5: Jump in loop
25
26. Now we discussed these type of loop.
1: While loop
The while loop in c programing repeatedly executes a target
statement as longas given condition is true.
Syntax. While(condition)
{
Statement(s);
}
Now we make program using of syntax.
While loop is decided initialization when u get variable. After makes
requirement conditioned and incrementand decrement.
26
27. Flowchart of while loop.
2: Do while loop.
A Do while loop similar to a while loop but except In fact that is
guaranteed to execute at least once time.
Syntax. Do
{
Statement
Increment and decrement
}
While(condition)
27
29. 3: The For loop.
A for loop is a repetitioncontrol of structure that allows you to
efficiently write a loop thatneeds to executes a specific of number time.
Syntax. For(initialization; condition; increment and decrement)
For(i=1;i<=100;i++)
{
Statement;
}
Now helping of syntax we make program.
For loop are used in pointer (you will read in after passing two
chapter)
And now your assignment is
Make program helpof for loop print one number on screen.
And now flowchart of for loop.
29
30. 4: Nested loop.
C programming allow to use one loop to inside another loop.
The nested loop are used in any loop.
Syntax.
30
31. Now make program helping of syntax.
.
5: jump in loop/control loop.
The jump in loop which process where we skipping and continue loop.
There are two type of statement of jump loop.
1: Breaking loop.
The terminate the loop statementand transfers execution to
the statement immediately.
2: Continueloop.
Causes the loop to skip the remainder of its body and
immediatelyretest its conditionprior to reiterating.
Now it’s time to making program of jump in loop.
Program jump in loop.
31
33. The Array
The array def.
The collection of same data type is knownas array.
Another definition of Array.
Arrays a kind of data structure that can store a fixed-size sequential
collection of elements of the same type. An array is used to store a
collection of data.
Syntax. Return type variable name[argument] and semicolon.
Example. type array Name [ array Size ];
There are three type of array
1: One dimensional array
2: Two dimensional array
3: Multiple dimensional array
1: One dimensional array.
The one dimensional array which subscript is one is known as 1d (one
dimensional) array.
Syntax. type array Name [ array Size];
Let’s make program help of syntax.
33
34. 1:Two-dimensional Arrays.
The simplest form of multidimensional array is the two-dimensional
array. A two-dimensional array is, in essence, a listof one-dimensional
arrays. To declare a two-dimensional integer array of size [x][y]
Syntax. type array Name [ x] [ y];
Now make program help of syntax.
34
35. 3: Multiple dimensional array.
C programming language allows multidimensional arrays. Here is the
general form of a multidimensional array declaration.
Syntax. type name[size1] [size2]...[size n];
Example. int threedim [5] [10] [4];
Let’s make program help of syntax.
Passing Arrays as Function Arguments.
pass a single-dimension array as an argument in a function, you
would have to declare a formal parameter in one of following three ways
and all three declaration methods produce similar results.
35
36. Program to merge two arrays and sorting in third array.
The program whichmake two array merge and get another array to
sorting both of arrays.
Example. 36
37. The merge program is your assignment.
Chapter 7
The Function
The function def. 37
38. A function is a group of statements that together perform a task.
Every C program has at least one function, which is main().
A function definitionin C programming consists of a function header
and a function body. Here are all the parts of a function:
Return Type:
A function may return a value. The return type is the data type of the
value the function returns. Some functions perform the desired
operations without returning a value. In this case, the return type is the
keyword void.
Function Name:
This is the actual name of the function. The function name and the
parameter list together constitute the function signature.
Parameters:
A parameter is like a placeholder. When a function is invoked, you pass
a value to the parameter. This value is referred to as actual parameter or
argument. The parameter list refers to the type,
order, and number of the parameters of a function. Parameters are
optional; that is, a function may contain no parameters.
Function Body:
The functionbody contains a collection of statements that define what
the function does.
Function Type
There are two type of function.
1: Built in function
The function whichalready defined in library.
Example. getch (), clrscr (), printf () and scanf () etc.
38
39. 2: User defined Function.
The function which declared/defined by user.
Example void disp (int, int); , #define max50 etc.
And now discussed element / method of user defined function.
There are three method of function.
1: Function declaration (optional).
2: Function defining.
3: Function call.
1: Function Declarations
A function declaration tells the compiler about a function name and how
to call the function. The actual body of the function can be defined
separately.
Syntax: return type function_name (parameter list );.
2: FunctionDefining.
A function definition provides the actual body of the function. The
function defining the declared function.
Syntax: return_type function_name( parameter list )
{
body of the function
}
3: Functioncall.
The function call is called parameter function in actual body of program.
39
40. Example. Function name (a, b);
There are two type of function call.
1: call by value.
The call by value method of passing arguments to a function copies the
actual value of an argument into the formal parameter of the function. In
this case, changes made to the parameter inside the function have no
effect on the argument.
Methods
void swap(int x, int y)
{
int temp;
temp = x; /* save the value of x */
x = y; /* put y into x */
y = temp; /* put temp into y */
return;
}
2: Call by reference(* reference).
The call by reference method of passing arguments to a function copies
the address of an argument into the formal parameter. Inside the
40
41. function, the address is used to access the actual argument used in the
call. It means the changes made to the parameter affect the passed
argument.
Method.
/* function definition to swapthe values */
void swap(int *x, int *y)
{
int temp;
temp = *x; /* save the value at address x */
*x = *y; /* puty intox */
*y = temp; /* put temp into y */
Category of Function
There are four category of function.
1: Function with arguments and return value.
e.g int add(int x ,inty)
2: function with argument andno return value.
e.g voidadd(intx , int y)
3: function with no argument and return value.
E.g int add(void)
4: Function with no argument and no return value.
e.g void add(void)
Chapter 8
41
42. The Recursion
Recursion def.
The Function which call function inself is known is recursion of the
fuction. The recusrionis requirement one functions as compare of nested
function.
Recursion Syntax.
int sub(int x)
int i,a;
-------
-------
I=sub(a); // Recursion
And Now helpof syntax make program of Recursion.
The Recursion program function declared thandefining there.
Chapter 9
42
43. The Pointer
Pointer def.
The pointer is specific variable which hold the address of another
variable. The pointer also known as reference and both of same symbol *.
Syntax.
{
Int a=100;
Int *p;
P=&a;
}
And now we make small program of pointer.
This program show how its’s value and address are holdby pointer.
Array Of Pointer
43
44. The process where we used array for many of same pointer is known as
array of pointer.
Syntax.
{
Int marks[]={10,20,30};
Int *pointer[3];
}
Here is program.
Pointer to Pointer.
The point/hold the pointer address is known as pointer to pointer or
chain of pointer.
Syntax.
44
45. And now make program of pointer to pointer help of given syntax.
Pointer to use in function.
The pointer passing in function as known as pointer passing in function.
C programming allows passing a pointer to a function. To do so, simply
declare the function parameter as a pointer type.
45
46. Explain program.
After linked to library program comes in function defining.write both
of them before swaping and before swaping . the swapping process is
t=*x here we value of x transfer in t than value of *y equal in *x here are
exchanging process. t value transfer in *y. I and j are store in *x and *y.
Chapter 10
46
47. The String
String def.
Strings are actually one-dimensional array of characters terminated by
a null character '0'. Thus a null-terminated string contains the characters
that comprise the string followed by a null.
Syntax.
char greeting [7] = {'s', 'a', 'b', 'e', 'e',’l’ '0'};
Program.
The program where we finding value, address and length of one by one
character.
47
48. Explain Program.
The program starts in main function. Gets string variable name and pass
parameter/argument thangive another variable to access and increment
for the string. The not (!) used for length of string also equal of the null 0.
Chapter 12
The Structure
Structure Def. 48
49. The structure is collection of the different data type. The keyword is
struct. The structure variable are declared in main() or after of curely
bracket.
structure is handle two and more member at that time.
structure size is equal is members size.
the members of address are madeup in sequencely,structure value
are not went one place to another place.
Syntax. struct struct name
{
<datatype> member 1;
<datatype> member 2;
}structure variable;
Declared main function syntax.
Struct struct name/tagvari1,vari2,vari3….vari n;
Example
int ,char,float are collection of different data type.
Person datail
Identity card
Name character value
Salary. Integer value
Etc.
Access of member in structure.
The structure which declared datatype these data type is called member
which we need variable to acess.structure is handle two and more
49
49
50. member at that time.structure size is equal is members size.the members
of address are madeup in sequencely,structure value are not wentone
place to another place.
(.)dot are used for access.
How ?
Structure variable . Structure member
There two mathod of access member.
First mathod
Secondmathod
Structure variable. Structure member
Struct
{
Int roll;
Char name[10];
}sturct={101,”sabeel”};
Printf(“roll number is %d”,struct.rool);
Struct student
{
Int roll;
Char name [10];
};
50
52. Array of Structure.
The array of structure are collection of different datatype which
collect different person.
Example result of five student.
Syntax.
Int mark [10];
Struct student
{
-------roll no;
-------name ;
} stu[5];
Here program.
52
53. Structure in structure / Nested in structure.
C program are allowed to structure have inside another structure as
known as struture in structure or nested in structure.
Syntax.
53
54. Accessing.
Calling outer variable
Outer variable . member1;
Calling inner variable
Outer variable . inner variable . member1;
And now make nested program help of syntax.
54
56. Chapter 13
The Union
Union Def.
The Union is collection of the different data type. store different data
types in the same memory location. You can define a union withmany
members, but only one member can contain a value at any given time.
The keyword is union. The union variable are declared in main() or after of
curely bracket.
union is handle one member at that time.
union size is equal is large members size.
The union member address in one cause when it’s large size
overwrite value is execute well but other variable during of
executed garbage value .
Syntax. union union name
{
<datatype> member 1;
<datatype> member 2;
}unionvariable;
56