SlideShare a Scribd company logo
1 of 44
PROGRAMMING with C
Basic Concept of Programming
Evolution of Programming!
HARDWARE
• Inputs To pin
outs
• Processed
using Gates
Assembly
language
• Added Strings
• Assembler
Directives
High Level
Languages
• Compilers
• Interpreters
A Basic C Program
#include<stdio.h>
void main(){
int no, index;
char * name[10];
printf(“ENTER NO OF STUDENTS:”);
scanf (“%d”, &n);
printf(“ENTER STUDENTS NAME:n”);
for(index=1;index<= no; index=index+1){
scanf(“%s”, name[index]);
}
printf(“NAME STARTS WITH ‘A’ ARE n:”);
for(index=1;index<= no; index=index+1){
if( name[index][0]==‘A’ || name[index][0]==‘a’){
printf(“t %s n”, name[index]);
}
}
}
How Programming works?
COMPILER
• Create a Program and COMPILE it
• WE will get an object code
OS
• On call, OS places it to RAM
• OS Pass Program ID to Scheduler
PROCESSOR
• Exchange values/data form I/O
• Execute Process
• Generates output
# Byte Reservation for Data Types
• For each variable to be stored, we have to allocate some
memory with specified size in Byte.
• 1 Byte=8 bits
• We can store characters from ANSI defined set.
• We can store Integers
• We can sore Floating Points/ Decimal format Numbers
• We can store Memory Addresses.
• Some programming languages use #void as a data type which
holds nothing(if variable) or holds anything(if data type)
ByteReservationChart
# One Thing to Notice
Sample Code:
signed int i=100
for(; i>0;i++);
printf(“%d”, i);
// In this pseudo code we assume, int takes exactly 1 byte
Output: _____?
# One Thing to Notice
Sample Code:
signed int i=100
for(; i<0;i++);
printf(“%d”, i);
// In this pseudo code we assume, int takes exactly 1 byte
Output: -128 !
// ranges from -128 to 127
So this loop go from: +100, +101, +102,………., +126, 127, -128;
STRUCTURE OF C PROGRAM
How to write a C Program?
32 Keywords forms the whole C
continue for auto int signed return
break while extern char unsigned void
case do static float enum goto
const if register double struct typedef
switch else long short union near
default volatile
>> This small keyword set makes the whole C powerful.
>> Its Libraries and Headers helps to simplify the programming.
>> The concept of POINTER and OPERATORS set helps to work in Hardware Level.
Operators in C.
DOMAIN OPERATORS
Arithmetic + - * / % ++ --
Relational == != > < <= >=
Logical && || !
Bitwise & | ^ ~ << >>
Assignment = += -= *= /= %= <<= >>=
Misc. sizeof() & * ?:
Arithmetic Operators : used in expressions
Relational Operators : used in relating values | returns Boolean value
Logical Operations : used in constructing Logical relations between Boolean value
returns Boolean value
Bitwise Operators : Manipulates data in Bit level ( 1011 1001)
Assignment Operators: Assigns R Value to L value
Sizeof() : Returns Size of data type in byte
& : Gives address of specified variable (Pointer)
* : Gives value at specified address (Pointer)
?: : inline conditions Syntax: (<condition>)?<if true>:<else>;
OPERATOR PRESIDENCE
• Right to Left – Start evaluate from Right
• Unary Operators
• Conditional Operators
• Assignment Operators
• Left To Right
• Everything Else such as Bitwise, Arithmetic etc.
CONTROL - FLOW
Program
Control Flow
Sequential Branching
Conditional
If else Switch
Unconditional
Goto
Iterative
For While Do while
VARIABLES
• Names given to those reserved memory location.
• In C ; a variable name have some constrains as per ANSI C regulations Rules
For Constructing Variable Name
• Characters Allowed :
• Underscore(_)
• Capital Letters ( A – Z )
• Small Letters ( a – z )
• Digits ( 0 – 9 )
• Blanks & Commas are not allowed
• No Special Symbols other than underscore(_) are allowed
• First Character should be alphabet or Underscore
• Variable name Should not be Reserved Word
• Variable have 2 parts
• R-value - [CONTENT of variable]
• L-value - [Address of Location]
Attributes of C Variable :
• 1.Name of Variable
• Variable name is only the name given to the “Memory address”.
• Variable name maps into “Address inside” and then by considering mapped address compiler
processes data.
• 2.Value inside Variable
• Depending on the type of Variable we can store any value of appropriate data type inside
Variable.
• 3.Address of Variable
• Variable can hold data ,it means there should be a container. So container must have Starting
Address.
• Address of variable = Starting Address of allocated Memory
• 4.Type of Variable
• Type of variable tells compiler that – “Allocate memory for data of Specified type“.
• 5.Size of Variable
• We can use sizeof operator to calculate size of any data type.
Main Function
• Till now we had use only one function. That is main();
• Main() is the only function which will be automatically called
on loading a program file
• There can be files without main function. In such cases, no
function will be called by default and nothing will execute until
we specifically call a function.
• So main() have nothing special than any other functions
• Compiler is the one which causes execution of main program
on call.
FUNCTION
• We can create enormous functions in a file.
• SYNTAX:
return type FUNCTION_NAME ( Parameter LIST)
{
……………………………
…………body…………
……………………………
return value;
}
int power( int a, int b) {
int result, i;
result=a;
for ( i=2; i<b; i++) {
result *= a;
}
return result;
}
void main(){
int p;
p = power(5,3);
printf(“%d”, a);
}
Local and Global Variables
• Local variables are variables inside a function can be used only
inside it.
• A variable declared out side the functions is known as Global
variables and can be used by any function. Changing value at
any function will change it globally.
Scope Lifetime and Visibility
• Each variable have its own scope, lifetime and visibility.
• SCOPE :- The region at which the value of a variable
can be used/Variable is in active state.
• LIFETIME :- The time period, where a variable is stored in
memory / RAM.
• VISIBILITY :- The set of program lines where a variable’s
value can be used / Variable is in active or
passive State.
Local and Global Variables
VARIABLE INSIDE
CALLED FUNCTION
GLOBAL VARIABLE VARIABLE INSIDE
CALLER FUNCTION
SCOPE Only Inside Local
Function
Everywhere inside
the program
Inside Caller and
Called function
LIFETIME From beginning of
function to end of
that local function.
From beginning of
program to end of
that program.
From beginning of
caller function to
end of that
function.
VISIBILITY Only inside Local
Function
Everywhere inside
the program
Only inside Caller
function
Data Structures
Array
Stack
Queue
Linked
List
Data Structures
• ARRAY – Data is stored in continuous memory locations
• LINKED LIST – Data is stored in separate pieces of memory
blocks and is linked to next block.
• STACK – Structures follow LAST IN FIRST OUT principle.
• QUEUE – Structures follow FIRST IN FIRST OUT principle.
Array
• “ int a[10];” initializes a location of 10*sizeof(int) space in
memory {10x 4bytes = 40 bytes};
• Each can be accessed by a[0], a[1], a[2], ……, a[8], a[9];
• Actually ‘var a’ become the pointer to the block of memory of
size 40 bytes.
• 0,1,2,3…. Are known as INDEX of array which are from
0 to (n-1);
STRING
• Strings are handled as an array of (char) type.
• Last character of array will be ‘0’
• Since an array, strings cannot be handled using normal
assignment operators or such;
• Header File Contains the string handling functions
#include<string.h>
• strcpy()
• strcat()
• strlen()
• strcmp()
• strchr()
• strstr()
Structure and Union
• Structure and Union are two type of user definable data
structures..
• Structure can be utilized for creating records; where Union can
be used for storing multiple type of data with only one data
per time.
TYPEDEF…
• Typedef is actually a keyword for assigning data types to a
Variable name;
|
| typedef unsigned int ROLLNO
|
DEFINE
• Typedef is actually a keyword for assigning permanent values
to a CONSTANT;
|
| #define PI 3.141521
|
#Type Casting
• CHAR and INT are interconvert able, since in ASCII Set,
Character is bind to an integer no between 0 and 255.
• To convert an expression to another type; we can use type cast.
• int x=3,y=2;
• printf(“ %.3fn”, (float) x/y);
• OUTPUT : “1”
• printf(“ %.3fn”, (float) x/y);
• OUTPUT : “1.500”
Weightage of Type Casting
INT
UNSIGNED INT
LONG
UNSIGNED LONG
LONG LONG
UNSIGNED LONG LONG
FLOAT
DOUBLE
LONG DOUBLE
RECURSION
• We know we can call any function from anywhere inside
another function
• In the same way; we can call any function from inside that
function.
• This is known as Recursion.
• This will create infinitely long execution
• In order to prevent that, one who call has to specify an
intelligent condition inside function
FILES AND I/O MANAGEMENT
How C Compiler Seek these things
STARNDERD I/O DEVICES
• STDIN -> Stranded Input Device : KEYBOARD
• STDOUT -> Stranded Output Device : MONITOR
I/O MANIPULATIONS.
• CHARACTER
• int getchar(void);
• int putchar(char c);
• STRING
• char *gets(void);
• int puts(char *s);
• GENERAL
• int scanf(const char *format);
• int printf(const char *format);
[%d, %c, %f, %s, %u, %x, %i,… ]
FILE HANDLERs
• FILE *fopen(const char *filename, const char *mode);
a FUNCTION
r Open file in read mode
w Open empty file in write mode if file not exist: error
a Open file with content in append mode if file not
exist: error; append mode appends data to existing.
r+ Open file in read/write mode mode
w+ Open in write mode; if file not exist: create;
a+ Open in append mode; if file not exist: create;
FILE MANIPULATIONS.
• CHARACTER
• int fgetc (FILE *fp);
• int fputc (int c, FILE *fp);
• STRING
• char *fgets(const char *s, int len, FILE *fp );
• int fputs(const char*c, FILE *fp);
• GENERAL
• int fscanf(FILE *fp, const char *format);
• int fprintf(FILE *fp, const char *format);
DYNAMIC MEMORY MANAGEMENT
Efficiency and Reliability depends on how Dynamic they are..
Memory Allocations
• Concept of HEAP AND STACK Memory
• void *calloc(int len, int size);
• Allocates array of length<-len, and block of size<-size
• Initialize location with 0;
• void free(void *address)
• Frees a piece of memory
• void *malloc(int num*sizeof (datatype))
• Allocates an array of num bytes
• void *realloc(void * address, int newsize)
• Extends parent size
COMMAND LINE ARGUMENTS
Parameters on call concept…
Command Line arguments
• It is possible to pass some values from the command line to your C
programs when they are executed. These values are called command line
arguments and many times they are important for your program especially
when you want to control your program from outside instead of hard coding
those values inside the code.
POINTERS
Hardware Level Thinking…
POINTERS and VOID
• Pointers are variables which stores address of another
memory location.
• Declaration : int *i; char* f; float* m[];
• Data Type Pointers define, which type of data is pointed by it.
• Functions can also be pointed by it.
• void *f; is the type which can hold any pointer;
• Function pointers are pointers to the address of first line of
function.
POINT 2D Array using Pointers
• p[i][j] === *(*(p+i)+j));

More Related Content

What's hot

CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsDhiviya Rose
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Ali Aminian
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambalajatin batra
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
CSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersCSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersDhiviya Rose
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Richard Thomson
 
C cpluplus 2
C cpluplus 2C cpluplus 2
C cpluplus 2sanya6900
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in cyazad dumasia
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
 

What's hot (20)

CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
C++
C++C++
C++
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
More on Lex
More on LexMore on Lex
More on Lex
 
Pointers
PointersPointers
Pointers
 
CSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersCSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and Pointers
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++
 
C cpluplus 2
C cpluplus 2C cpluplus 2
C cpluplus 2
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Scala functions
Scala functionsScala functions
Scala functions
 
Yacc lex
Yacc lexYacc lex
Yacc lex
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centre
 

Viewers also liked

Viewers also liked (7)

Vinay-2016
Vinay-2016Vinay-2016
Vinay-2016
 
ich gcp principles
ich gcp principlesich gcp principles
ich gcp principles
 
PeerReview
PeerReviewPeerReview
PeerReview
 
Raman Pandey updated Resume
Raman Pandey updated ResumeRaman Pandey updated Resume
Raman Pandey updated Resume
 
12051 en lghp2
12051 en lghp212051 en lghp2
12051 en lghp2
 
E-book barometer Q3 2015
E-book barometer Q3 2015E-book barometer Q3 2015
E-book barometer Q3 2015
 
Java
JavaJava
Java
 

Similar to C

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]Abhishek Sinha
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptUdhayaKumar175069
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in Cummeafruz
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.pptAlefya1
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxvanshhans21102005
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxSreeLaya9
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++Manzoor ALam
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxshivam460694
 

Similar to C (20)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
C programming
C programmingC programming
C programming
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
C programming language
C programming languageC programming language
C programming language
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
02basics
02basics02basics
02basics
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Unit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptxUnit I - 1R introduction to R program.pptx
Unit I - 1R introduction to R program.pptx
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
C language
C languageC language
C language
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
 

More from Jerin John

Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Jerin John
 
Who will control the Future
Who will control the FutureWho will control the Future
Who will control the FutureJerin John
 
Logic development
Logic developmentLogic development
Logic developmentJerin John
 

More from Jerin John (6)

Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
 
Who will control the Future
Who will control the FutureWho will control the Future
Who will control the Future
 
Arduino
ArduinoArduino
Arduino
 
Logic development
Logic developmentLogic development
Logic development
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 

Recently uploaded

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 

Recently uploaded (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 

C

  • 1. PROGRAMMING with C Basic Concept of Programming
  • 2. Evolution of Programming! HARDWARE • Inputs To pin outs • Processed using Gates Assembly language • Added Strings • Assembler Directives High Level Languages • Compilers • Interpreters
  • 3. A Basic C Program #include<stdio.h> void main(){ int no, index; char * name[10]; printf(“ENTER NO OF STUDENTS:”); scanf (“%d”, &n); printf(“ENTER STUDENTS NAME:n”); for(index=1;index<= no; index=index+1){ scanf(“%s”, name[index]); } printf(“NAME STARTS WITH ‘A’ ARE n:”); for(index=1;index<= no; index=index+1){ if( name[index][0]==‘A’ || name[index][0]==‘a’){ printf(“t %s n”, name[index]); } } }
  • 4. How Programming works? COMPILER • Create a Program and COMPILE it • WE will get an object code OS • On call, OS places it to RAM • OS Pass Program ID to Scheduler PROCESSOR • Exchange values/data form I/O • Execute Process • Generates output
  • 5. # Byte Reservation for Data Types • For each variable to be stored, we have to allocate some memory with specified size in Byte. • 1 Byte=8 bits • We can store characters from ANSI defined set. • We can store Integers • We can sore Floating Points/ Decimal format Numbers • We can store Memory Addresses. • Some programming languages use #void as a data type which holds nothing(if variable) or holds anything(if data type)
  • 7. # One Thing to Notice Sample Code: signed int i=100 for(; i>0;i++); printf(“%d”, i); // In this pseudo code we assume, int takes exactly 1 byte Output: _____?
  • 8. # One Thing to Notice Sample Code: signed int i=100 for(; i<0;i++); printf(“%d”, i); // In this pseudo code we assume, int takes exactly 1 byte Output: -128 ! // ranges from -128 to 127 So this loop go from: +100, +101, +102,………., +126, 127, -128;
  • 9. STRUCTURE OF C PROGRAM How to write a C Program?
  • 10. 32 Keywords forms the whole C continue for auto int signed return break while extern char unsigned void case do static float enum goto const if register double struct typedef switch else long short union near default volatile >> This small keyword set makes the whole C powerful. >> Its Libraries and Headers helps to simplify the programming. >> The concept of POINTER and OPERATORS set helps to work in Hardware Level.
  • 11. Operators in C. DOMAIN OPERATORS Arithmetic + - * / % ++ -- Relational == != > < <= >= Logical && || ! Bitwise & | ^ ~ << >> Assignment = += -= *= /= %= <<= >>= Misc. sizeof() & * ?: Arithmetic Operators : used in expressions Relational Operators : used in relating values | returns Boolean value Logical Operations : used in constructing Logical relations between Boolean value returns Boolean value Bitwise Operators : Manipulates data in Bit level ( 1011 1001) Assignment Operators: Assigns R Value to L value Sizeof() : Returns Size of data type in byte & : Gives address of specified variable (Pointer) * : Gives value at specified address (Pointer) ?: : inline conditions Syntax: (<condition>)?<if true>:<else>;
  • 12. OPERATOR PRESIDENCE • Right to Left – Start evaluate from Right • Unary Operators • Conditional Operators • Assignment Operators • Left To Right • Everything Else such as Bitwise, Arithmetic etc.
  • 13. CONTROL - FLOW Program Control Flow Sequential Branching Conditional If else Switch Unconditional Goto Iterative For While Do while
  • 14. VARIABLES • Names given to those reserved memory location. • In C ; a variable name have some constrains as per ANSI C regulations Rules For Constructing Variable Name • Characters Allowed : • Underscore(_) • Capital Letters ( A – Z ) • Small Letters ( a – z ) • Digits ( 0 – 9 ) • Blanks & Commas are not allowed • No Special Symbols other than underscore(_) are allowed • First Character should be alphabet or Underscore • Variable name Should not be Reserved Word • Variable have 2 parts • R-value - [CONTENT of variable] • L-value - [Address of Location]
  • 15. Attributes of C Variable : • 1.Name of Variable • Variable name is only the name given to the “Memory address”. • Variable name maps into “Address inside” and then by considering mapped address compiler processes data. • 2.Value inside Variable • Depending on the type of Variable we can store any value of appropriate data type inside Variable. • 3.Address of Variable • Variable can hold data ,it means there should be a container. So container must have Starting Address. • Address of variable = Starting Address of allocated Memory • 4.Type of Variable • Type of variable tells compiler that – “Allocate memory for data of Specified type“. • 5.Size of Variable • We can use sizeof operator to calculate size of any data type.
  • 16. Main Function • Till now we had use only one function. That is main(); • Main() is the only function which will be automatically called on loading a program file • There can be files without main function. In such cases, no function will be called by default and nothing will execute until we specifically call a function. • So main() have nothing special than any other functions • Compiler is the one which causes execution of main program on call.
  • 17. FUNCTION • We can create enormous functions in a file. • SYNTAX: return type FUNCTION_NAME ( Parameter LIST) { …………………………… …………body………… …………………………… return value; } int power( int a, int b) { int result, i; result=a; for ( i=2; i<b; i++) { result *= a; } return result; } void main(){ int p; p = power(5,3); printf(“%d”, a); }
  • 18. Local and Global Variables • Local variables are variables inside a function can be used only inside it. • A variable declared out side the functions is known as Global variables and can be used by any function. Changing value at any function will change it globally.
  • 19. Scope Lifetime and Visibility • Each variable have its own scope, lifetime and visibility. • SCOPE :- The region at which the value of a variable can be used/Variable is in active state. • LIFETIME :- The time period, where a variable is stored in memory / RAM. • VISIBILITY :- The set of program lines where a variable’s value can be used / Variable is in active or passive State.
  • 20. Local and Global Variables VARIABLE INSIDE CALLED FUNCTION GLOBAL VARIABLE VARIABLE INSIDE CALLER FUNCTION SCOPE Only Inside Local Function Everywhere inside the program Inside Caller and Called function LIFETIME From beginning of function to end of that local function. From beginning of program to end of that program. From beginning of caller function to end of that function. VISIBILITY Only inside Local Function Everywhere inside the program Only inside Caller function
  • 22. Data Structures • ARRAY – Data is stored in continuous memory locations • LINKED LIST – Data is stored in separate pieces of memory blocks and is linked to next block. • STACK – Structures follow LAST IN FIRST OUT principle. • QUEUE – Structures follow FIRST IN FIRST OUT principle.
  • 23. Array • “ int a[10];” initializes a location of 10*sizeof(int) space in memory {10x 4bytes = 40 bytes}; • Each can be accessed by a[0], a[1], a[2], ……, a[8], a[9]; • Actually ‘var a’ become the pointer to the block of memory of size 40 bytes. • 0,1,2,3…. Are known as INDEX of array which are from 0 to (n-1);
  • 24. STRING • Strings are handled as an array of (char) type. • Last character of array will be ‘0’ • Since an array, strings cannot be handled using normal assignment operators or such; • Header File Contains the string handling functions #include<string.h> • strcpy() • strcat() • strlen() • strcmp() • strchr() • strstr()
  • 25. Structure and Union • Structure and Union are two type of user definable data structures.. • Structure can be utilized for creating records; where Union can be used for storing multiple type of data with only one data per time.
  • 26.
  • 27.
  • 28. TYPEDEF… • Typedef is actually a keyword for assigning data types to a Variable name; | | typedef unsigned int ROLLNO |
  • 29. DEFINE • Typedef is actually a keyword for assigning permanent values to a CONSTANT; | | #define PI 3.141521 |
  • 30. #Type Casting • CHAR and INT are interconvert able, since in ASCII Set, Character is bind to an integer no between 0 and 255. • To convert an expression to another type; we can use type cast. • int x=3,y=2; • printf(“ %.3fn”, (float) x/y); • OUTPUT : “1” • printf(“ %.3fn”, (float) x/y); • OUTPUT : “1.500”
  • 31. Weightage of Type Casting INT UNSIGNED INT LONG UNSIGNED LONG LONG LONG UNSIGNED LONG LONG FLOAT DOUBLE LONG DOUBLE
  • 32. RECURSION • We know we can call any function from anywhere inside another function • In the same way; we can call any function from inside that function. • This is known as Recursion. • This will create infinitely long execution • In order to prevent that, one who call has to specify an intelligent condition inside function
  • 33. FILES AND I/O MANAGEMENT How C Compiler Seek these things
  • 34. STARNDERD I/O DEVICES • STDIN -> Stranded Input Device : KEYBOARD • STDOUT -> Stranded Output Device : MONITOR
  • 35. I/O MANIPULATIONS. • CHARACTER • int getchar(void); • int putchar(char c); • STRING • char *gets(void); • int puts(char *s); • GENERAL • int scanf(const char *format); • int printf(const char *format); [%d, %c, %f, %s, %u, %x, %i,… ]
  • 36. FILE HANDLERs • FILE *fopen(const char *filename, const char *mode); a FUNCTION r Open file in read mode w Open empty file in write mode if file not exist: error a Open file with content in append mode if file not exist: error; append mode appends data to existing. r+ Open file in read/write mode mode w+ Open in write mode; if file not exist: create; a+ Open in append mode; if file not exist: create;
  • 37. FILE MANIPULATIONS. • CHARACTER • int fgetc (FILE *fp); • int fputc (int c, FILE *fp); • STRING • char *fgets(const char *s, int len, FILE *fp ); • int fputs(const char*c, FILE *fp); • GENERAL • int fscanf(FILE *fp, const char *format); • int fprintf(FILE *fp, const char *format);
  • 38. DYNAMIC MEMORY MANAGEMENT Efficiency and Reliability depends on how Dynamic they are..
  • 39. Memory Allocations • Concept of HEAP AND STACK Memory • void *calloc(int len, int size); • Allocates array of length<-len, and block of size<-size • Initialize location with 0; • void free(void *address) • Frees a piece of memory • void *malloc(int num*sizeof (datatype)) • Allocates an array of num bytes • void *realloc(void * address, int newsize) • Extends parent size
  • 40. COMMAND LINE ARGUMENTS Parameters on call concept…
  • 41. Command Line arguments • It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard coding those values inside the code.
  • 43. POINTERS and VOID • Pointers are variables which stores address of another memory location. • Declaration : int *i; char* f; float* m[]; • Data Type Pointers define, which type of data is pointed by it. • Functions can also be pointed by it. • void *f; is the type which can hold any pointer; • Function pointers are pointers to the address of first line of function.
  • 44. POINT 2D Array using Pointers • p[i][j] === *(*(p+i)+j));