SlideShare a Scribd company logo
1 of 26
Download to read offline
With/Mohamed Fawzy
C-Programming Language-2015
1 Day #2
2
Lecture Notes:
 Set your phone to vibration mode.
 Ask any time.
 During labs feel free to check any materials or internet.
Contents
3
Arrays.
Control statements.
Pointers.
Functions.
Dynamically memory allocation
4
Arrays.
 which can store a fixed-size sequential collection of elements of the
same type.
 All arrays consist of contiguous memory locations (Single Block).
 The size of array, once declared, is fixed and cannot be modified.
 Single Dimension Array.
 Multi Dimension Array (Array of Arrays).
EX:
char a[5]; //Array of 5 characters.
EX:
char a[3][4];
/*Array of three arrays
and each array has 4 characters.*/
5
Examples:
double d[100]={1.5,2.7};
//first two elements initialized and remaining ones set to zero.
short num[]={1,2,3,4,5,6};
//compiler fixes size at 7 elements.
short num[]={1,2,3,4,5,6};
//compiler fixes size at 7 elements.
6
Take Care !!!!
#define size 10
int a[size];
char size=10;
int a[size];
const char size=10;
int a[size];
int a[5.3];
//size must be an integer
int a[5];
a[5]=50;
//in this case it will overwrite some data.
a[-1]=5;
//the index must be an integer.
7
Control Statements.
 For Statements.
for (initial value;condition;update)
{
//statements
}
OR
initial value;
for(;condition;)
{
//statements
update;
}
8
Take Care !!!!
char x;
for(x=0;x<200;x++)
{
printf(“c programming”);
}
for(;;)
{
printf(“c programming”);
}
9
 while loop.
while (condition)
{
//statements
}
 do while loop.
do
{
//statements
}
while (condition)
Control Statements.
10
Break & Continue.
• Break and continue are used to modify the execution of loops.
 break.
When the break statement is encountered inside a loop, the loop is immediately
terminated and program control resumes at the next statement following the loop.
 Continue.
continue forces the next iteration of the loop to take place, skipping
any code in between.
11
Examples:
//program to print even numbers between(0:50)
int main()
{
char x=0;
while (x<=50)
{
if(x%2){
x++;
continue;
}
printf("%dn",x++);
}
return 0;
}
12
Pointers.
Why pointers?
• Achieve call by reference with functions.
• Arrays and structures are difficult without pointers.
• Create linked list, trees and graph.
Note:
We must take care in using pointers since, there are no safety features.
13
Declaring pointers.
• Pointers are declared using “*”.
Int x; //declaring an integer
Int* x; //declaring pointer to an integer
char* m; //declare pointer to character
Notes:
• Pointers may only point to variables of the same type as the pointer
has been declared.
• A pointer to an int may only point to int.
• A pointer to a double may only point to double not float or long double.
• (&) stands for “address of….”
• (*) stands for “content of…”
14
Example:
15
Take Care !!!!
16
Pointers and arrays.
• The name of array is a pointer to the 0th place of array.
• You cannot apply increment or decrement on array name.
• Pointer is useful for passing array to function and safe stack memory.
EX#1:
double *ptr;
double arr[10];
Ptr=arr; //ptr=&arr[0]
arr++; //not allowed
ptr++; //allowed
EX#2:
void print_arr(char *ptr){
printf(“%dn”,*(ptr++));
}
. . . . . . . . . . .
char arr[10];
Print_arr(arr);
Take Care !!!!
char *ptr[5]; //array of five pointers to char
char (*ptr)[5]; //pointer to array of 5 elements
17
EX#3:
char (*ptr)[5];
char arr[5] {5,6,7,8,9};
Ptr=arr;
ptr++;
5
0
1
2
3
4
5
6
7
8
9
Garbage value
18
Functions.
• Functions are blocks of code that perform a number of pre-defined commands to
accomplish something productive. You can either use the built-in library functions
or you can create your own functions.
• Functions that a programmer writes will generally require a prototype.
• It tells the compiler what the function will return, what the function will be called,
as well as what arguments the function can be passed.
return-type <function-name> (arg_type arg1, arg_type arg2,…);
Exs.
void fun (void); //function which take nothing and return nothing
void fun (int x,int y,…); //function take arguments and return nothing
int fun (void); //function take nothing and return int
int fun (int x,int y,…); //function take arguments and return int
19
Ex#1.
#include <stdio.h>
int mult ( int x, int y ); //prototype of function
int main()
{
int x,int y,int result;
printf( "Please input two numbers to be multiplied: " );
scanf( "%d", &x );
scanf( "%d", &y );
result= mult(x,y); //calling the function
printf( "The product of two numbers is %dn",result);
return 0;
}
//implementation of function
int mult (int x, int y)
{
return x * y;
}
Functions. cont‟d
Pointer to function.
20
What happened in calling function?
Save some data in memory segment called stack.
• the value of PC (Program Counter).
• A copy of parameters passed to function.
• The value which returned from function.
Note:
If size of data stored on stack is larger than whole stack size it will cause
Common error called “Stack Overflow”.
Problem:
What if we need to pass a huge data to function to be processed.
Solution:
We can pass by reference because any pointer only occupy 4 bytes.
Functions. cont‟d
Calling function.
21
Write a c program to calculate the largest number in passed array.
#include <studio.h>
char calc_largest (char *ptr,char siz)
{
char largest=*ptr;
char i=0;
for (i=0;i<siz;i++)
{
if (*(ptr+i) >largest)
largest=*(ptr+i);
else
continue;
}
return largest;
}
int main(){
char arr[]={45,12,5,44,6,8,60}
printf(“the largest value is %d”,calc_largest(arr,sizeof(arr));
}
Functions. cont‟d
22
Functions. cont‟d
Pointer to function.
• Pointer to function allow programmers to pass a function as a
parameter to another function.
• Function pointer syntax.
<return data_type> (* pointer_name)(arguments passed to function);
EX#1:
void (*ptr)(int arg1,int arg2);
/*
Pointer to function which return nothing and take two
integers parameters.
*/
Note:
Don't be confused between pointer to function and pointer to array.
23
Functions. cont‟d
Initializing Pointer to function.
EX#2:
void my_int_func(int x)
{
printf( "%dn", x );
}
int main()
{
void (*ptr)(int);
/* the ampersand is actually optional */
ptr = &my_int_func;
(*ptr)( 2 ); //or ptr(2);
return 0;
}
24
Hands ON
Email: mo7amed.fawzy33@gmail.com
Phone: 01006032792
Facebook: mo7amed_fawzy33@yahoo.com
Contact me:
25
26

More Related Content

What's hot (20)

Pointers in C
Pointers in CPointers in C
Pointers in C
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
C pointers
C pointersC pointers
C pointers
 
Pointers - DataStructures
Pointers - DataStructuresPointers - DataStructures
Pointers - DataStructures
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
Pointers
PointersPointers
Pointers
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
 
Pointers
 Pointers Pointers
Pointers
 
Void pointer in c
Void pointer in cVoid pointer in c
Void pointer in c
 
Ponters
PontersPonters
Ponters
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 

Viewers also liked

C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.Mohamed Fawzy
 
02 Interfacing High Power Devices.2016
02 Interfacing High Power Devices.201602 Interfacing High Power Devices.2016
02 Interfacing High Power Devices.2016Mohamed Fawzy
 
Ximea - the pc camera, 90 gflps smart camera
Ximea  - the pc camera, 90 gflps smart cameraXimea  - the pc camera, 90 gflps smart camera
Ximea - the pc camera, 90 gflps smart cameraXIMEA
 
Embedded Systems: Lecture 6: Linux & GNU
Embedded Systems: Lecture 6: Linux & GNUEmbedded Systems: Lecture 6: Linux & GNU
Embedded Systems: Lecture 6: Linux & GNUAhmed El-Arabawy
 
Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Ahmed El-Arabawy
 
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux Box
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux BoxEmbedded Systems: Lecture 8: The Raspberry Pi as a Linux Box
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux BoxAhmed El-Arabawy
 
Lecture 15 ryuzo okada - vision processors for embedded computer vision
Lecture 15   ryuzo okada - vision processors for embedded computer visionLecture 15   ryuzo okada - vision processors for embedded computer vision
Lecture 15 ryuzo okada - vision processors for embedded computer visionmustafa sarac
 
Intelligent Video Surveillance - Synesis integrated hardware and software sol...
Intelligent Video Surveillance - Synesis integrated hardware and software sol...Intelligent Video Surveillance - Synesis integrated hardware and software sol...
Intelligent Video Surveillance - Synesis integrated hardware and software sol...Nikolai Ptitsyn
 
Embedded Systems: Lecture 7: Unwrapping the Raspberry Pi
Embedded Systems: Lecture 7: Unwrapping the Raspberry PiEmbedded Systems: Lecture 7: Unwrapping the Raspberry Pi
Embedded Systems: Lecture 7: Unwrapping the Raspberry PiAhmed El-Arabawy
 
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry PiEmbedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry PiAhmed El-Arabawy
 
Embedded Systems: Lecture 5: A Tour in RTOS Land
Embedded Systems: Lecture 5: A Tour in RTOS LandEmbedded Systems: Lecture 5: A Tour in RTOS Land
Embedded Systems: Lecture 5: A Tour in RTOS LandAhmed El-Arabawy
 
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi APEmbedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi APAhmed El-Arabawy
 
Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Ahmed El-Arabawy
 
Embedded Systems: Lecture 2: Introduction to Embedded Systems
Embedded Systems: Lecture 2: Introduction to Embedded SystemsEmbedded Systems: Lecture 2: Introduction to Embedded Systems
Embedded Systems: Lecture 2: Introduction to Embedded SystemsAhmed El-Arabawy
 
Embedded Systems: Lecture 4: Selecting the Proper RTOS
Embedded Systems: Lecture 4: Selecting the Proper RTOSEmbedded Systems: Lecture 4: Selecting the Proper RTOS
Embedded Systems: Lecture 4: Selecting the Proper RTOSAhmed El-Arabawy
 
Course 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesCourse 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesAhmed El-Arabawy
 
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Ahmed El-Arabawy
 
Embedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewEmbedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewAhmed El-Arabawy
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Ahmed El-Arabawy
 

Viewers also liked (20)

C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.
 
02 Interfacing High Power Devices.2016
02 Interfacing High Power Devices.201602 Interfacing High Power Devices.2016
02 Interfacing High Power Devices.2016
 
Towards Embedded Computer Vision邁向嵌入式電腦視覺
Towards Embedded Computer Vision邁向嵌入式電腦視覺Towards Embedded Computer Vision邁向嵌入式電腦視覺
Towards Embedded Computer Vision邁向嵌入式電腦視覺
 
Ximea - the pc camera, 90 gflps smart camera
Ximea  - the pc camera, 90 gflps smart cameraXimea  - the pc camera, 90 gflps smart camera
Ximea - the pc camera, 90 gflps smart camera
 
Embedded Systems: Lecture 6: Linux & GNU
Embedded Systems: Lecture 6: Linux & GNUEmbedded Systems: Lecture 6: Linux & GNU
Embedded Systems: Lecture 6: Linux & GNU
 
Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu Course 101: Lecture 6: Installing Ubuntu
Course 101: Lecture 6: Installing Ubuntu
 
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux Box
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux BoxEmbedded Systems: Lecture 8: The Raspberry Pi as a Linux Box
Embedded Systems: Lecture 8: The Raspberry Pi as a Linux Box
 
Lecture 15 ryuzo okada - vision processors for embedded computer vision
Lecture 15   ryuzo okada - vision processors for embedded computer visionLecture 15   ryuzo okada - vision processors for embedded computer vision
Lecture 15 ryuzo okada - vision processors for embedded computer vision
 
Intelligent Video Surveillance - Synesis integrated hardware and software sol...
Intelligent Video Surveillance - Synesis integrated hardware and software sol...Intelligent Video Surveillance - Synesis integrated hardware and software sol...
Intelligent Video Surveillance - Synesis integrated hardware and software sol...
 
Embedded Systems: Lecture 7: Unwrapping the Raspberry Pi
Embedded Systems: Lecture 7: Unwrapping the Raspberry PiEmbedded Systems: Lecture 7: Unwrapping the Raspberry Pi
Embedded Systems: Lecture 7: Unwrapping the Raspberry Pi
 
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry PiEmbedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
Embedded Systems: Lecture 7: Lab 1: Preparing the Raspberry Pi
 
Embedded Systems: Lecture 5: A Tour in RTOS Land
Embedded Systems: Lecture 5: A Tour in RTOS LandEmbedded Systems: Lecture 5: A Tour in RTOS Land
Embedded Systems: Lecture 5: A Tour in RTOS Land
 
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi APEmbedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
Embedded Systems: Lecture 8: Lab 1: Building a Raspberry Pi Based WiFi AP
 
Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2)
 
Embedded Systems: Lecture 2: Introduction to Embedded Systems
Embedded Systems: Lecture 2: Introduction to Embedded SystemsEmbedded Systems: Lecture 2: Introduction to Embedded Systems
Embedded Systems: Lecture 2: Introduction to Embedded Systems
 
Embedded Systems: Lecture 4: Selecting the Proper RTOS
Embedded Systems: Lecture 4: Selecting the Proper RTOSEmbedded Systems: Lecture 4: Selecting the Proper RTOS
Embedded Systems: Lecture 4: Selecting the Proper RTOS
 
Course 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment VariablesCourse 102: Lecture 11: Environment Variables
Course 102: Lecture 11: Environment Variables
 
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
 
Embedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course OverviewEmbedded Systems: Lecture 1: Course Overview
Embedded Systems: Lecture 1: Course Overview
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
 

Similar to C-Programming Language Arrays Functions Pointers

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 

Similar to C-Programming Language Arrays Functions Pointers (20)

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
C++_notes.pdf
C++_notes.pdfC++_notes.pdf
C++_notes.pdf
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Unit 3
Unit 3 Unit 3
Unit 3
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C programming language
C programming languageC programming language
C programming language
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
C
CC
C
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 

More from Mohamed Fawzy

07 Analogue to Digital Converter(ADC).2016
07 Analogue to Digital Converter(ADC).201607 Analogue to Digital Converter(ADC).2016
07 Analogue to Digital Converter(ADC).2016Mohamed Fawzy
 
06 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.201606 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.2016Mohamed Fawzy
 
05 EEPROM memory.2016
05 EEPROM memory.201605 EEPROM memory.2016
05 EEPROM memory.2016Mohamed Fawzy
 
04 Interfacing LCD Displays.2016
04 Interfacing LCD Displays.201604 Interfacing LCD Displays.2016
04 Interfacing LCD Displays.2016Mohamed Fawzy
 
01 GPIO||General Purpose Input Output.2016
01 GPIO||General Purpose Input Output.201601 GPIO||General Purpose Input Output.2016
01 GPIO||General Purpose Input Output.2016Mohamed Fawzy
 
00 let us get started.2016
00 let us get started.201600 let us get started.2016
00 let us get started.2016Mohamed Fawzy
 
أزاى تروح فى داهيه !!!
أزاى تروح فى داهيه !!!أزاى تروح فى داهيه !!!
أزاى تروح فى داهيه !!!Mohamed Fawzy
 

More from Mohamed Fawzy (10)

07 Analogue to Digital Converter(ADC).2016
07 Analogue to Digital Converter(ADC).201607 Analogue to Digital Converter(ADC).2016
07 Analogue to Digital Converter(ADC).2016
 
06 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.201606 Interfacing Keypad 4x4.2016
06 Interfacing Keypad 4x4.2016
 
05 EEPROM memory.2016
05 EEPROM memory.201605 EEPROM memory.2016
05 EEPROM memory.2016
 
04 Interfacing LCD Displays.2016
04 Interfacing LCD Displays.201604 Interfacing LCD Displays.2016
04 Interfacing LCD Displays.2016
 
01 GPIO||General Purpose Input Output.2016
01 GPIO||General Purpose Input Output.201601 GPIO||General Purpose Input Output.2016
01 GPIO||General Purpose Input Output.2016
 
00 let us get started.2016
00 let us get started.201600 let us get started.2016
00 let us get started.2016
 
أزاى تروح فى داهيه !!!
أزاى تروح فى داهيه !!!أزاى تروح فى داهيه !!!
أزاى تروح فى داهيه !!!
 
Ce from a to z
Ce from a to zCe from a to z
Ce from a to z
 
Taqa
TaqaTaqa
Taqa
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 

Recently uploaded

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 

C-Programming Language Arrays Functions Pointers

  • 2. 2 Lecture Notes:  Set your phone to vibration mode.  Ask any time.  During labs feel free to check any materials or internet.
  • 4. 4 Arrays.  which can store a fixed-size sequential collection of elements of the same type.  All arrays consist of contiguous memory locations (Single Block).  The size of array, once declared, is fixed and cannot be modified.  Single Dimension Array.  Multi Dimension Array (Array of Arrays). EX: char a[5]; //Array of 5 characters. EX: char a[3][4]; /*Array of three arrays and each array has 4 characters.*/
  • 5. 5 Examples: double d[100]={1.5,2.7}; //first two elements initialized and remaining ones set to zero. short num[]={1,2,3,4,5,6}; //compiler fixes size at 7 elements. short num[]={1,2,3,4,5,6}; //compiler fixes size at 7 elements.
  • 6. 6 Take Care !!!! #define size 10 int a[size]; char size=10; int a[size]; const char size=10; int a[size]; int a[5.3]; //size must be an integer int a[5]; a[5]=50; //in this case it will overwrite some data. a[-1]=5; //the index must be an integer.
  • 7. 7 Control Statements.  For Statements. for (initial value;condition;update) { //statements } OR initial value; for(;condition;) { //statements update; }
  • 8. 8 Take Care !!!! char x; for(x=0;x<200;x++) { printf(“c programming”); } for(;;) { printf(“c programming”); }
  • 9. 9  while loop. while (condition) { //statements }  do while loop. do { //statements } while (condition) Control Statements.
  • 10. 10 Break & Continue. • Break and continue are used to modify the execution of loops.  break. When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.  Continue. continue forces the next iteration of the loop to take place, skipping any code in between.
  • 11. 11 Examples: //program to print even numbers between(0:50) int main() { char x=0; while (x<=50) { if(x%2){ x++; continue; } printf("%dn",x++); } return 0; }
  • 12. 12 Pointers. Why pointers? • Achieve call by reference with functions. • Arrays and structures are difficult without pointers. • Create linked list, trees and graph. Note: We must take care in using pointers since, there are no safety features.
  • 13. 13 Declaring pointers. • Pointers are declared using “*”. Int x; //declaring an integer Int* x; //declaring pointer to an integer char* m; //declare pointer to character Notes: • Pointers may only point to variables of the same type as the pointer has been declared. • A pointer to an int may only point to int. • A pointer to a double may only point to double not float or long double. • (&) stands for “address of….” • (*) stands for “content of…”
  • 16. 16 Pointers and arrays. • The name of array is a pointer to the 0th place of array. • You cannot apply increment or decrement on array name. • Pointer is useful for passing array to function and safe stack memory. EX#1: double *ptr; double arr[10]; Ptr=arr; //ptr=&arr[0] arr++; //not allowed ptr++; //allowed EX#2: void print_arr(char *ptr){ printf(“%dn”,*(ptr++)); } . . . . . . . . . . . char arr[10]; Print_arr(arr); Take Care !!!! char *ptr[5]; //array of five pointers to char char (*ptr)[5]; //pointer to array of 5 elements
  • 17. 17 EX#3: char (*ptr)[5]; char arr[5] {5,6,7,8,9}; Ptr=arr; ptr++; 5 0 1 2 3 4 5 6 7 8 9 Garbage value
  • 18. 18 Functions. • Functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create your own functions. • Functions that a programmer writes will generally require a prototype. • It tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. return-type <function-name> (arg_type arg1, arg_type arg2,…); Exs. void fun (void); //function which take nothing and return nothing void fun (int x,int y,…); //function take arguments and return nothing int fun (void); //function take nothing and return int int fun (int x,int y,…); //function take arguments and return int
  • 19. 19 Ex#1. #include <stdio.h> int mult ( int x, int y ); //prototype of function int main() { int x,int y,int result; printf( "Please input two numbers to be multiplied: " ); scanf( "%d", &x ); scanf( "%d", &y ); result= mult(x,y); //calling the function printf( "The product of two numbers is %dn",result); return 0; } //implementation of function int mult (int x, int y) { return x * y; } Functions. cont‟d Pointer to function.
  • 20. 20 What happened in calling function? Save some data in memory segment called stack. • the value of PC (Program Counter). • A copy of parameters passed to function. • The value which returned from function. Note: If size of data stored on stack is larger than whole stack size it will cause Common error called “Stack Overflow”. Problem: What if we need to pass a huge data to function to be processed. Solution: We can pass by reference because any pointer only occupy 4 bytes. Functions. cont‟d Calling function.
  • 21. 21 Write a c program to calculate the largest number in passed array. #include <studio.h> char calc_largest (char *ptr,char siz) { char largest=*ptr; char i=0; for (i=0;i<siz;i++) { if (*(ptr+i) >largest) largest=*(ptr+i); else continue; } return largest; } int main(){ char arr[]={45,12,5,44,6,8,60} printf(“the largest value is %d”,calc_largest(arr,sizeof(arr)); } Functions. cont‟d
  • 22. 22 Functions. cont‟d Pointer to function. • Pointer to function allow programmers to pass a function as a parameter to another function. • Function pointer syntax. <return data_type> (* pointer_name)(arguments passed to function); EX#1: void (*ptr)(int arg1,int arg2); /* Pointer to function which return nothing and take two integers parameters. */ Note: Don't be confused between pointer to function and pointer to array.
  • 23. 23 Functions. cont‟d Initializing Pointer to function. EX#2: void my_int_func(int x) { printf( "%dn", x ); } int main() { void (*ptr)(int); /* the ampersand is actually optional */ ptr = &my_int_func; (*ptr)( 2 ); //or ptr(2); return 0; }
  • 25. Email: mo7amed.fawzy33@gmail.com Phone: 01006032792 Facebook: mo7amed_fawzy33@yahoo.com Contact me: 25
  • 26. 26