SlideShare a Scribd company logo
1 of 48
C Programming
1
by
Nitesh Saitwal
BE CSE
C programming---basic
1 Introduction to C
2 C Fundamentals
3 Formatted Input/Output
4 Expression
5 Selection Statement
6 Loops
7 Basic Types
8 Arrays
9 Functions
10 Pointers
11 Pointers and Arrays
12 Structure
What is C
 C is an ANSI/ISO standard and powerful
programming language for developing real time
applications. C programming language was invented
by Dennis Ritchie at the Bell Laboratories in 1972.
 C programming is most widely used programming
language even today. All other programming
languages were derived directly or indirectly from C
programming concepts. C programming is the basic for
all programming languages.
The C Character Set
 A character denotes any alphabet, digit or special
symbol used to represent information.
Alphabets – A,B,…………Y,Z
a,b,………….y,z
Digits - 0,1,2,3,4,5,6,7,8,9
Special symbols - ~’@#$%^&*()+-/*+,-:;”<>.?/
Constant, Variables and Keywords
C Variables
variables in c are memory location that are
given names and can be assigned values. The two basic
kind of variables in C which are numeric and character.
Numeric variable
Numeric variables can either be
integer values or real values .
Character variable
Character variable are character
value.
C Constant
The different between variable and constant is
that variable can change their value at any time but constant
can never change their value.
Types of C Constants
Primary Constants-
integer, Real, Character
Secondary Constants-
Array, Pointer, Structure
C Keywords
Keywords are the word whose meaning
has already been explained to the compiler.
Some C keywords are
auto, double, int, struct, break, else,
long , Continue, do, if, while…….upto 32.
Operators in C programming
Arithmetic Operators
Increment and Decrement Operators
Assignment Operators
Relational Operators
Logical Operators
Conditional Operators
Arithmetic Operators
Operator Meaning of Operator
+ addition or unary plus
- subtraction or unary minus
* multiplication
/ division
% remainder after division( modulo
division)
Increment and decrement operators
Example-
Let a=5 and b=10
a++; //a becomes 6
a--; //a becomes 5
++a; //a becomes 6
--a; //a becomes 5
Assignment Operators
The most common assignment operator is =.
This operator assigns the value in right side to
the left side.
For example:
var =5 //5 is assigned to var
a=c; //value of c is assigned to a
5=c; // Error! 5 is a constant.
Relational Operator
Relational operators checks relationship
between two operands. If the relation is true,
it returns value 1 and if the relation is false, it
returns value 0.
< Less than <= Less than or equal to
> Greater than >= Greater than or equal
== Equal to != Not equal to
Logical Operators
OPERATORS MEANING OF OPERATOR
&& Logical AND
|| Logical OR
! Logical NOT
Conditional Operator
The condition operator consists of two symbols
the question mark(?) and the colon (:).
exp1?exp2:exp3
Example-
c=(c>0)?10:-10;
Example 1
#include <stdio.h>
// program reads and prints the same thing
int main() {
int number ;
printf (“ Enter a Number: ”);
scanf (“%d”, &number);
printf (“Number is %dn”, number);
return 0;
}
Output : Enter a number: 4
Number is 4
Preprocessor directives
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
The #include directives “paste” the contents of the files
stdio.h, stdlib.h and string.h into your source code, at
the very place where the directives appear.
These files contain information about some library
functions used in the program:
 stdio stands for “standard I/O”, stdlib stands for “standard
library”, and string.h includes useful string manipulation
functions.
What is main()
 main() is a function.
 When a program begins running, the system calls the
function main() which marks the entry point of the
program.
main() are enclosed within a pair of braces {} as
shown below.
int main()
{
Statement1;
Statement2;
Statement3;
}
Input / Output
printf (); //used to print to console(screen)
scanf (); //used to take an input from
console(user).
example: printf(“%c”, ’a’); scanf(“%d”, &a);
More format specifiers
%c The character format specifier.
%d The integer format specifier.
%i The integer format specifier (same as %d).
%f The floating-point format specifier.
%o The unsigned octal format specifier.
%s The string format specifier.
%u The unsigned integer format specifier.
%x The unsigned hexadecimal format specifier.
%% Outputs a percent sign.
C – Decision Control statement
In decision control statements (C if else and
nested if), group of statements are executed
when condition is true. If condition is false,
then else part statements are executed.
There are 3 types of decision making control
statements in C language. They are,
• if statements
• if else statements
• nested if statements
Decision control statements
If
In these type of statements, if condition is true,
then respective block of code is executed.
Syntax-
if (condition)
{
Statements;
}
Decision control statements
if…else
In these type of statements, group of
statements are executed when condition is
true. If condition is false, then else part
statements are executed.
Syntax-
if (condition)
{ Statement1; Statement2;}
else
{ Statement3; Statement4; }
Decision control statements
nested if
If condition 1 is false, then condition 2 is
checked and statements are executed if it is
true. If condition 2 also gets failure, then else part
is executed.
Syntax-
if (condition1)
{ Statement1; }
else_if (condition2)
{ Statement2; }
else Statement 3;
C – Loop control statements
 Loop control statements in C are used to
perform looping operations until the given
condition is true. Control comes out of the loop
statements once condition becomes false.
There are 3 types of loop control statements in C
language. They are,
for
while
do-while
For loop control statement
 For loop is made up of 3 parts inside its brackets which are
separated by semicolons.
Syntax-
for (exp1; exp2; expr3)
{ statements; }
Where,
exp1 – variable initialization
( Example: i=0, j=2, k=3 )
exp2 – condition checking
( Example: i>5, j<3, k=3 )
exp3 – increment/decrement
( Example: ++i, j–, ++k )
while loop control statement
While loop often the case in programming
that you want to do something a fixed
number of times.
Syntax-
while (condition)
{ statements; }
where,
condition might be a>5, i<10
do while loop control statement
Do while loop same as while loop except that
its text condition at the bottom of the loop.
Syntax
do { statements; }
while (condition);
where,
condition might be a>5, i<10
C – Case control statements
 The statements which are used to execute
only specific block of statements in a series of
blocks are called case control statements.
There are 4 types of case control statements
in C language. They are,
– break
– continue
– goto
break control statements
Break statement is used to terminate the while
loops, switch case loops and for loops from the
subsequent execution.
We often comes across situation where we want
to jump out of a loop instantly, without waiting to
get back the condition test.
Syntax:
break;
Example program for break statement in C:
#include <stdio.h>
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5)
{
printf("nComing out of for loop when i = 5");
break;
}
printf("%d ",i);
}
}
Continue statement in C:
Continue statement is used to continue the next
iteration of for loop, while loop and do-while
loops. So, the remaining statements are skipped
within the loop for that particular iteration.
Syntax :
continue;
Example program for continue statement in C:
#include <stdio.h>
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5 || i==6)
{
printf("nSkipping %d from display using "  "continue statement n",i);
continue;
}
printf("%d ",i);
}
}
goto statement in C:
goto statements is used to transfer the normal flow of a
program to the specified label in the program.
Below is the syntax for goto statement in C.
{
…….
go to label;
…….
…….
LABEL:
statements;
}
What is Array
 Array is a collection of variables belongings to
the same data type. You can store group of
data of same data type in an array.
• Array might be belonging to any of the data types
• Array size must be a constant value.
• Always, Contiguous (adjacent) memory locations
are used to store array elements in memory.
• It is a best practice to initialize an array to zero or
null while declaring, if we don’t assign any values
to array.
Example program for array in C:
#include<stdio.h>
int main()
{
int i;
int arr[5] = {10,20,30,40,50};
// declaring and Initializing array in C
//To initialize all array elements to 0, use int arr[5]={0};
/* Above array can be initialized as below also
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
*/
for (i=0;i<5;i++)
{
// Accessing each variable
printf("value of arr[%d] is %d n", i, arr[i]);
}
}
Output
value of arr[0] is 10
value of arr[1] is 20
value of arr[2] is 30
value of arr[3] is 40
value of arr[4] is 50
What is String
 C Strings are nothing but array of characters ended with null
character (‘0’).
 This null character indicates the end of the string.
 Strings are always enclosed by double quotes. Whereas, character
is enclosed by single quotes in C.
 Example for C string:
 char string*20+ = , ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ , ‘2’ , ‘r’ , ‘e’ , ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ ,
‘0’-; (or)
 char string*20+ = “fresh2refresh”; (or)
 char string [] = “fresh2refresh”;
 Difference between above declarations are, when we declare char
as “string*20+“, 20 bytes of memory space is allocated for holding
the string value.
 When we declare char as “string*+“, memory space will be allocated
as per the requirement during execution of the program.
Example program for C string:
#include <stdio.h>
int main ()
{
char string*20+ = “hello ";
printf("The string is : %s n", string );
return 0;
}
Output:
The string is : hello
C String functions:
String.h header file supports all the string
functions in C language.
 strlen()
 strcpy()
 strcat()
 strcmp()
C – strlen() function
strlen( ) function in C gives the length of the given
string. Syntax for strlen( ) function is given below.
size_t strlen ( const char * str );
strlen( ) function counts the number of characters
in a given string and returns the integer value.
It stops counting the character when null
character is found. Because, null character
indicates the end of the string in C.
C – strcpy() function
strcpy( ) function copies contents of one string
into another string. Syntax for strcpy function is
given below.
char * strcpy ( char * destination, const char *
source );
Example:
strcpy ( str1, str2) – It copies contents of str2 into
str1.
strcpy ( str2, str1) – It copies contents of str1 into
str2.
C – strncat() function
• strncat( ) function in C language concatenates (
appends ) portion of one string at the end of another
string. Syntax for strncat( ) function is given below.
• char * strncat ( char * destination, const char * source,
size_t num );
• Example :
• strncat ( str2, str1, 3 ); – First 3 characters of str1 is
concatenated at the end of str2.
strncat ( str1, str2, 3 ); - First 3 characters of str2 is
concatenated at the end of str1.
• As you know, each string in C is ended up with null
character (‘0′).
C – strcmp() function
• strcmp( ) function in C compares two given
strings and returns zero if they are same.
• If length of string1 < string2, it returns < 0
value. If length of string1 > string2, it returns > 0
value. Syntax for strcmp( ) function is given
below.
• int strcmp ( const char * str1, const char * str2 );
• strcmp( ) function is case sensitive. i.e, “A” and
“a” are treated as different characters.
C – Pointer
• C Pointer is a variable that stores/points the
address of the another variable.
• C Pointer is used to allocate memory dynamically
i.e. at run time.
• The variable might be any of the data type such
as int, float, char, double, short etc.
• Syntax : data_type *var_name;
Example : int *p; char *p;
• Where, * is used to denote that “p” is pointer
variable and not a normal variable.
Example program for pointer in C:
#include <stdio.h>
int main()
{
int *ptr, q;
q = 50;
/* address of q is assigned to ptr */
ptr = &q;
/* display q's value using ptr variable */
printf("%d", *ptr);
return 0;
}
• Output:
50
What is Function
 A function is self-contained block of statements
that perform a coherent task of some kind.
 function is something like hiring a person to do
a specific job for you.
 A large C program is divided into basic building
blocks called C function. C function contains set
of instructions enclosed by “, -” which performs
specific operation in a C program. Actually,
Collection of these functions creates a C program.
example program for C function:
#include<stdio.h>
float square ( float x ); // function prototype, also called function declaration
int main( ) // main function, program starts from here
{ float m, n ;
printf ( "nEnter some number for finding square n");
scanf ( "%f", &m ) ;
// function call
n = square ( m ) ;
printf ( "nSquare of the given number %f is %f",m,n );
}
float square ( float x ) // function definition
{
float p ;
p = x * x ;
return ( p ) ;
}
• Output- Enter some number for finding square 2
Square of the given number 2.000000 is 4.000000
C – Structure
• C Structure is a collection of different data types
which are grouped together and each element in
a C structure is called member.
• If you want to access structure members in C,
structure variable should be declared.
• Many structure variables can be declared for
same structure and memory will be allocated for
each separately.
• It is a best practice to initialize a structure to null
while declaring, if we don’t assign any values to
structure members.
Example program for C structure:
#include <stdio.h>
#include <string.h>
struct student
{
int id;
char name[20];
float percentage;
};
int main()
{
struct student record = {0}; //Initializing to null
record.id=1;
strcpy(record.name, "Ram");
record.percentage = 86.5;
printf(" Id is: %d n", record.id);
printf(" Name is: %s n", record.name);
printf(" Percentage is: %f n", record.percentage);
return 0;
}
• Output:
Id is: 1
Name is: Ram
Percentage is: 86.500000
End of seminar
Doubts && Queries?

More Related Content

What's hot

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D arraySangani Ankur
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++aleenaguen
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programAAKASH KUMAR
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program executionRumman Ansari
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in cPrabhu Govind
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++Ashok Raj
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Ankur Pandey
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 

What's hot (20)

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Strings in C
Strings in CStrings in C
Strings in C
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 

Viewers also liked

Data Structure Part II
Data Structure Part IIData Structure Part II
Data Structure Part IINANDINI SHARMA
 
Computer Architecture & Organization
Computer Architecture & OrganizationComputer Architecture & Organization
Computer Architecture & OrganizationNANDINI SHARMA
 
Distributed system unit II according to syllabus of RGPV, Bhopal
Distributed system unit II according to syllabus of  RGPV, BhopalDistributed system unit II according to syllabus of  RGPV, Bhopal
Distributed system unit II according to syllabus of RGPV, BhopalNANDINI SHARMA
 
Distributed system notes unit I
Distributed system notes unit IDistributed system notes unit I
Distributed system notes unit INANDINI SHARMA
 
Distributed & parallel system
Distributed & parallel systemDistributed & parallel system
Distributed & parallel systemManish Singh
 
Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systemskaran2190
 

Viewers also liked (10)

Training report
Training reportTraining report
Training report
 
Distributed System ppt
Distributed System pptDistributed System ppt
Distributed System ppt
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
 
Data Structure Part II
Data Structure Part IIData Structure Part II
Data Structure Part II
 
Computer Architecture & Organization
Computer Architecture & OrganizationComputer Architecture & Organization
Computer Architecture & Organization
 
Distributed system unit II according to syllabus of RGPV, Bhopal
Distributed system unit II according to syllabus of  RGPV, BhopalDistributed system unit II according to syllabus of  RGPV, Bhopal
Distributed system unit II according to syllabus of RGPV, Bhopal
 
Distributed System
Distributed System Distributed System
Distributed System
 
Distributed system notes unit I
Distributed system notes unit IDistributed system notes unit I
Distributed system notes unit I
 
Distributed & parallel system
Distributed & parallel systemDistributed & parallel system
Distributed & parallel system
 
Unit 1 architecture of distributed systems
Unit 1 architecture of distributed systemsUnit 1 architecture of distributed systems
Unit 1 architecture of distributed systems
 

Similar to What is c

Similar to What is c (20)

C Programming
C ProgrammingC Programming
C Programming
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C operators
C operatorsC operators
C operators
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
Lec 10
Lec 10Lec 10
Lec 10
 
C tutorial
C tutorialC tutorial
C tutorial
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
C tutorial
C tutorialC tutorial
C tutorial
 
Looping statements
Looping statementsLooping statements
Looping statements
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

What is c

  • 2. C programming---basic 1 Introduction to C 2 C Fundamentals 3 Formatted Input/Output 4 Expression 5 Selection Statement 6 Loops 7 Basic Types 8 Arrays 9 Functions 10 Pointers 11 Pointers and Arrays 12 Structure
  • 3. What is C  C is an ANSI/ISO standard and powerful programming language for developing real time applications. C programming language was invented by Dennis Ritchie at the Bell Laboratories in 1972.  C programming is most widely used programming language even today. All other programming languages were derived directly or indirectly from C programming concepts. C programming is the basic for all programming languages.
  • 4. The C Character Set  A character denotes any alphabet, digit or special symbol used to represent information. Alphabets – A,B,…………Y,Z a,b,………….y,z Digits - 0,1,2,3,4,5,6,7,8,9 Special symbols - ~’@#$%^&*()+-/*+,-:;”<>.?/
  • 5. Constant, Variables and Keywords C Variables variables in c are memory location that are given names and can be assigned values. The two basic kind of variables in C which are numeric and character. Numeric variable Numeric variables can either be integer values or real values . Character variable Character variable are character value.
  • 6. C Constant The different between variable and constant is that variable can change their value at any time but constant can never change their value. Types of C Constants Primary Constants- integer, Real, Character Secondary Constants- Array, Pointer, Structure
  • 7. C Keywords Keywords are the word whose meaning has already been explained to the compiler. Some C keywords are auto, double, int, struct, break, else, long , Continue, do, if, while…….upto 32.
  • 8. Operators in C programming Arithmetic Operators Increment and Decrement Operators Assignment Operators Relational Operators Logical Operators Conditional Operators
  • 9. Arithmetic Operators Operator Meaning of Operator + addition or unary plus - subtraction or unary minus * multiplication / division % remainder after division( modulo division)
  • 10. Increment and decrement operators Example- Let a=5 and b=10 a++; //a becomes 6 a--; //a becomes 5 ++a; //a becomes 6 --a; //a becomes 5
  • 11. Assignment Operators The most common assignment operator is =. This operator assigns the value in right side to the left side. For example: var =5 //5 is assigned to var a=c; //value of c is assigned to a 5=c; // Error! 5 is a constant.
  • 12. Relational Operator Relational operators checks relationship between two operands. If the relation is true, it returns value 1 and if the relation is false, it returns value 0. < Less than <= Less than or equal to > Greater than >= Greater than or equal == Equal to != Not equal to
  • 13. Logical Operators OPERATORS MEANING OF OPERATOR && Logical AND || Logical OR ! Logical NOT
  • 14. Conditional Operator The condition operator consists of two symbols the question mark(?) and the colon (:). exp1?exp2:exp3 Example- c=(c>0)?10:-10;
  • 15. Example 1 #include <stdio.h> // program reads and prints the same thing int main() { int number ; printf (“ Enter a Number: ”); scanf (“%d”, &number); printf (“Number is %dn”, number); return 0; } Output : Enter a number: 4 Number is 4
  • 16. Preprocessor directives #include <stdio.h> #include <stdlib.h> #include <string.h> The #include directives “paste” the contents of the files stdio.h, stdlib.h and string.h into your source code, at the very place where the directives appear. These files contain information about some library functions used in the program:  stdio stands for “standard I/O”, stdlib stands for “standard library”, and string.h includes useful string manipulation functions.
  • 17. What is main()  main() is a function.  When a program begins running, the system calls the function main() which marks the entry point of the program. main() are enclosed within a pair of braces {} as shown below. int main() { Statement1; Statement2; Statement3; }
  • 18. Input / Output printf (); //used to print to console(screen) scanf (); //used to take an input from console(user). example: printf(“%c”, ’a’); scanf(“%d”, &a); More format specifiers %c The character format specifier. %d The integer format specifier. %i The integer format specifier (same as %d). %f The floating-point format specifier. %o The unsigned octal format specifier. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier. %% Outputs a percent sign.
  • 19. C – Decision Control statement In decision control statements (C if else and nested if), group of statements are executed when condition is true. If condition is false, then else part statements are executed. There are 3 types of decision making control statements in C language. They are, • if statements • if else statements • nested if statements
  • 20. Decision control statements If In these type of statements, if condition is true, then respective block of code is executed. Syntax- if (condition) { Statements; }
  • 21. Decision control statements if…else In these type of statements, group of statements are executed when condition is true. If condition is false, then else part statements are executed. Syntax- if (condition) { Statement1; Statement2;} else { Statement3; Statement4; }
  • 22. Decision control statements nested if If condition 1 is false, then condition 2 is checked and statements are executed if it is true. If condition 2 also gets failure, then else part is executed. Syntax- if (condition1) { Statement1; } else_if (condition2) { Statement2; } else Statement 3;
  • 23. C – Loop control statements  Loop control statements in C are used to perform looping operations until the given condition is true. Control comes out of the loop statements once condition becomes false. There are 3 types of loop control statements in C language. They are, for while do-while
  • 24. For loop control statement  For loop is made up of 3 parts inside its brackets which are separated by semicolons. Syntax- for (exp1; exp2; expr3) { statements; } Where, exp1 – variable initialization ( Example: i=0, j=2, k=3 ) exp2 – condition checking ( Example: i>5, j<3, k=3 ) exp3 – increment/decrement ( Example: ++i, j–, ++k )
  • 25. while loop control statement While loop often the case in programming that you want to do something a fixed number of times. Syntax- while (condition) { statements; } where, condition might be a>5, i<10
  • 26. do while loop control statement Do while loop same as while loop except that its text condition at the bottom of the loop. Syntax do { statements; } while (condition); where, condition might be a>5, i<10
  • 27. C – Case control statements  The statements which are used to execute only specific block of statements in a series of blocks are called case control statements. There are 4 types of case control statements in C language. They are, – break – continue – goto
  • 28. break control statements Break statement is used to terminate the while loops, switch case loops and for loops from the subsequent execution. We often comes across situation where we want to jump out of a loop instantly, without waiting to get back the condition test. Syntax: break;
  • 29. Example program for break statement in C: #include <stdio.h> int main() { int i; for(i=0;i<10;i++) { if(i==5) { printf("nComing out of for loop when i = 5"); break; } printf("%d ",i); } }
  • 30. Continue statement in C: Continue statement is used to continue the next iteration of for loop, while loop and do-while loops. So, the remaining statements are skipped within the loop for that particular iteration. Syntax : continue;
  • 31. Example program for continue statement in C: #include <stdio.h> int main() { int i; for(i=0;i<10;i++) { if(i==5 || i==6) { printf("nSkipping %d from display using " "continue statement n",i); continue; } printf("%d ",i); } }
  • 32. goto statement in C: goto statements is used to transfer the normal flow of a program to the specified label in the program. Below is the syntax for goto statement in C. { ……. go to label; ……. ……. LABEL: statements; }
  • 33. What is Array  Array is a collection of variables belongings to the same data type. You can store group of data of same data type in an array. • Array might be belonging to any of the data types • Array size must be a constant value. • Always, Contiguous (adjacent) memory locations are used to store array elements in memory. • It is a best practice to initialize an array to zero or null while declaring, if we don’t assign any values to array.
  • 34. Example program for array in C: #include<stdio.h> int main() { int i; int arr[5] = {10,20,30,40,50}; // declaring and Initializing array in C //To initialize all array elements to 0, use int arr[5]={0}; /* Above array can be initialized as below also arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50; */ for (i=0;i<5;i++) { // Accessing each variable printf("value of arr[%d] is %d n", i, arr[i]); } } Output value of arr[0] is 10 value of arr[1] is 20 value of arr[2] is 30 value of arr[3] is 40 value of arr[4] is 50
  • 35. What is String  C Strings are nothing but array of characters ended with null character (‘0’).  This null character indicates the end of the string.  Strings are always enclosed by double quotes. Whereas, character is enclosed by single quotes in C.  Example for C string:  char string*20+ = , ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ , ‘2’ , ‘r’ , ‘e’ , ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ , ‘0’-; (or)  char string*20+ = “fresh2refresh”; (or)  char string [] = “fresh2refresh”;  Difference between above declarations are, when we declare char as “string*20+“, 20 bytes of memory space is allocated for holding the string value.  When we declare char as “string*+“, memory space will be allocated as per the requirement during execution of the program.
  • 36. Example program for C string: #include <stdio.h> int main () { char string*20+ = “hello "; printf("The string is : %s n", string ); return 0; } Output: The string is : hello
  • 37. C String functions: String.h header file supports all the string functions in C language.  strlen()  strcpy()  strcat()  strcmp()
  • 38. C – strlen() function strlen( ) function in C gives the length of the given string. Syntax for strlen( ) function is given below. size_t strlen ( const char * str ); strlen( ) function counts the number of characters in a given string and returns the integer value. It stops counting the character when null character is found. Because, null character indicates the end of the string in C.
  • 39. C – strcpy() function strcpy( ) function copies contents of one string into another string. Syntax for strcpy function is given below. char * strcpy ( char * destination, const char * source ); Example: strcpy ( str1, str2) – It copies contents of str2 into str1. strcpy ( str2, str1) – It copies contents of str1 into str2.
  • 40. C – strncat() function • strncat( ) function in C language concatenates ( appends ) portion of one string at the end of another string. Syntax for strncat( ) function is given below. • char * strncat ( char * destination, const char * source, size_t num ); • Example : • strncat ( str2, str1, 3 ); – First 3 characters of str1 is concatenated at the end of str2. strncat ( str1, str2, 3 ); - First 3 characters of str2 is concatenated at the end of str1. • As you know, each string in C is ended up with null character (‘0′).
  • 41. C – strcmp() function • strcmp( ) function in C compares two given strings and returns zero if they are same. • If length of string1 < string2, it returns < 0 value. If length of string1 > string2, it returns > 0 value. Syntax for strcmp( ) function is given below. • int strcmp ( const char * str1, const char * str2 ); • strcmp( ) function is case sensitive. i.e, “A” and “a” are treated as different characters.
  • 42. C – Pointer • C Pointer is a variable that stores/points the address of the another variable. • C Pointer is used to allocate memory dynamically i.e. at run time. • The variable might be any of the data type such as int, float, char, double, short etc. • Syntax : data_type *var_name; Example : int *p; char *p; • Where, * is used to denote that “p” is pointer variable and not a normal variable.
  • 43. Example program for pointer in C: #include <stdio.h> int main() { int *ptr, q; q = 50; /* address of q is assigned to ptr */ ptr = &q; /* display q's value using ptr variable */ printf("%d", *ptr); return 0; } • Output: 50
  • 44. What is Function  A function is self-contained block of statements that perform a coherent task of some kind.  function is something like hiring a person to do a specific job for you.  A large C program is divided into basic building blocks called C function. C function contains set of instructions enclosed by “, -” which performs specific operation in a C program. Actually, Collection of these functions creates a C program.
  • 45. example program for C function: #include<stdio.h> float square ( float x ); // function prototype, also called function declaration int main( ) // main function, program starts from here { float m, n ; printf ( "nEnter some number for finding square n"); scanf ( "%f", &m ) ; // function call n = square ( m ) ; printf ( "nSquare of the given number %f is %f",m,n ); } float square ( float x ) // function definition { float p ; p = x * x ; return ( p ) ; } • Output- Enter some number for finding square 2 Square of the given number 2.000000 is 4.000000
  • 46. C – Structure • C Structure is a collection of different data types which are grouped together and each element in a C structure is called member. • If you want to access structure members in C, structure variable should be declared. • Many structure variables can be declared for same structure and memory will be allocated for each separately. • It is a best practice to initialize a structure to null while declaring, if we don’t assign any values to structure members.
  • 47. Example program for C structure: #include <stdio.h> #include <string.h> struct student { int id; char name[20]; float percentage; }; int main() { struct student record = {0}; //Initializing to null record.id=1; strcpy(record.name, "Ram"); record.percentage = 86.5; printf(" Id is: %d n", record.id); printf(" Name is: %s n", record.name); printf(" Percentage is: %f n", record.percentage); return 0; } • Output: Id is: 1 Name is: Ram Percentage is: 86.500000
  • 48. End of seminar Doubts && Queries?