12 cprogramming
TRANSCRIPT
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 1/33
Overview Of C
Programming
Overview Of C
Programming
Niranjana.S.Karandikar
MSc-I
Roll No.12
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 2/33
Contents• Introduction
• Compiler vs Interpreter
• Basic structure of a C program
• Data Type
• Functions
• Operators
• Decision Making Statements
• Loops
• Arrays
• Pointers
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 3/33
Introduction• C was invented to write an operating system calledUNIX.
• C is a successor of B language, which wasintroduced around 1970.
• The language was formalized in 1988 by the
American Nationa Stan ar Institute. ANSI .
• The UNIX OS was totally written in C by 1973.
• Today, C is the most widely used and popular System
Programming Language.• Most of the state-of-the-art softwares have been
implemented using C.
• Today's most ][popular Linux OS and RBDMSMySQL have been written in C.
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 4/33
Compiler vs Interpretor• Compiler:
Source Code Object Code
• Interpreter reads the source code of your program one line
at a time,performing the specific instructions
contained in that line
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 6/33
Keywords• The following list shows the reserved words
in C. These reserved words may not be used
as constant or variable or any other.
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 7/33
auto double int struct
break else long switch
case enum register typedef
char extern short union
const float signed unsigned
continue for return void
default goto Size of volatile
do if static while
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 8/33
Data Types• A set of values that a variable can store
along with a set of operations that can be
performed on that variable.
char
int
float ----06 digits of precision
double -–10 digits of precision
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 10/33
operators Arithmatic Operators
o Operator Action
• – Subtraction
• +
• * Multiplication
• / Division
• % Modulus• –– Decrement
• ++ Increment
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 11/33
Relational Operators
• Relational Operators
o Operator Action
•
> Greater than =
• < Less than
• <= Less than or equal
• = = Equal
• != Not equal
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 12/33
Logical Operators
• Operator Action
• && AND
• | | OR• ! NOT
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 13/33
Decision making statements
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 14/33
if
Syntax
if(boolean_expression)
{
/* statement(s) will execute if the boolean expression is true */
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 15/33
if...else statement• Syntaxif(boolean_expression)
{
/* statement(s) will execute if the boolean expression is true */
}
else
{
/* statement(s) will execute if the boolean expression is false */
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 16/33
if...else if...else Statement
if(boolean_expression 1)
{
/* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2)
{* *
}
else if( boolean_expression 3)
{
/* Executes when the boolean expression 3 is true */
}else
{
/* executes when the none of the above condition is true */
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 17/33
Nested if statements
if( boolean_expression 1)
{
/* Executes when the boolean expression 1 is
true */
oo ean_express on
{
/* Executes when the boolean expression 2 is
true */}
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 18/33
switch statement
switch(expression){
case constant-expression :
statement(s);
break; /* optional */
case constant-ex ression :
statement(s);
break; /* optional */
/* you can have any number of case statements */
default : /* Optional */statement(s);
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 20/33
Loops
Break and Continue
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 21/33
while loop in C
• A while loop statement in C programminglanguage repeatedly executes a target statement as long as a given condition is
true.
• Syntax
while(condition)
{
statement(s);
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 23/33
for loop
• A for loop is a repetition controlstructure that allows you to efficientlywrite a loop that needs to execute a
specific number of times.
•
for ( init; condition; increment )
{
statement(s);
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 25/33
do...while loop
• A do...while loop is similar to a while loop,except that a do...while loop is guaranteedto execute at least one time.
•
Syntax
{
statement(s);
}while( condition );
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 27/33
Arrays
• An array is used to store a collection of
data, but it is often more useful to think
of an array as a collection of variables of
.
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 28/33
• To declare an array in C, a programmer
specifies the type of the elements and thenumber of elements required by an array as
follows:
Type arrayName [ arraySize ];
#include <stdio.h>
int main ()
{
int n[ 10 ]; /* n is an array of 10 integers */
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 29/33
Pointers
• Pointers are aptly name: they "point" to
locations in memory.
•
Syntax <varia e_type> <name>;
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 30/33
#include <stdio.h>
int main()
{
int x; /* A normal integer*/
int *p; /* A pointer to an integer ("*p" is aninteger, so p must be a pointer to an integer) */
= &x * Read it "assi n the address of x to " *
scanf( "%d", &x ); /* Put a value in x, we couldalso use p here */
printf( "%d\n", *p ); /* Note the use of the * to
get the value */getchar();
}
7/27/2019 12 Cprogramming
http://slidepdf.com/reader/full/12-cprogramming 31/33
References
• Balguruswami, Programming with C
• Mc Graw-Hill-C-The Complete reference
•Ritchie,R.,The C Programming
Language,1988
• http://www.tutorialspoint.com/cprogramm
ing/cprogramming_tutorial.pdf
• http://www.cprogramming.com/
• http://www.howstuffworks.com/c.htm