SlideShare a Scribd company logo
1 of 46
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],pointer to a function that takes an integer argument and a float argument and returns an integer pointer to a function that takes an integer argument and a float argument and returns a  pointer  to an integer An  array  of pointers to functions – Each function takes an integer argument and a float argument and returns a pointer to an integer
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
Void Pointers CS 3090: Safety Critical Programming in C
[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CS 3090: Safety Critical Programming in C
A C programmer cannot not decides what will be the memory address of any variables.
[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object]
[object Object],CS 3090: Safety Critical Programming in C Far Pointer
09/27/11 CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
CS 3090: Safety Critical Programming in C ,[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object]
#include<stdio.h> int main(int argc, char *argv[]) { printf(&quot;No. of Argument::%d&quot;,argc); int cnt=argc-1; while(cnt>=1) { printf(&quot;Entered numbers are%s&quot;,argv[cnt]); cnt--; }return 0;}
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
typedef struct IntNode { int value; struct IntNode *next; } INTNODE; INTNODE *search_list(INTNODE *node, int const key) { while (!node) { if (node->value == key) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C OK, but it only works for nodes containing integer data. If you want a list of strings, you’ll need to define a new type and new function.
typedef struct Node { void *value; struct Node *next; } NODE; void construct_node(NODE *node, void *value, NODE *next) { node->value = value; node->next = next; } NODE *new_node(void *value, NODE *next) { NODE *node = (NODE *)malloc(sizeof(NODE)); construct_node(node, value, next); return node; } CS 3090: Safety Critical Programming in C void*  is compatible with any pointer type. So, this member can hold (a pointer to) any value!
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
NODE *search_list(NODE *node, void const *key, int (*compare)(void const *, void const *)) { while (node) { if (!compare(node->value, key)) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C Assumption:  compare  returns zero if its parameter values are equal; nonzero otherwise
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C Note: you may get a warning, since  strcmp  is not strictly of the right type: its parameters are of type  char *  rather than  void * &  is optional here – compiler will implicitly take the address
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C Array of pointers to functions. Each function takes two  double s and returns a  double
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C 3 argc argc [0] [1] [2] [3] NUL
int main(int argc, char **argv) { char id[ID_LIMIT]; switch(argc) { case 1: generate_ID(id); break; case 3: if (strcmp(argv[1], &quot;-i&quot;) exit(INVALID_ARG); strcpy(id, argv[2]); break; default: exit(INVALID_ARG_COUNT); } register(id); } CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C

More Related Content

What's hot

Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programmingIcaii Infotech
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming AssignmentVijayananda Mohire
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08Terry Yoast
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in CUri Dekel
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework HelpC++ Homework Help
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 

What's hot (19)

Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Code generator
Code generatorCode generator
Code generator
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
C pointers
C pointersC pointers
C pointers
 
Ponters
PontersPonters
Ponters
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
C
CC
C
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework Help
 
String & its application
String & its applicationString & its application
String & its application
 

Viewers also liked

Viewers also liked (7)

9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
C pointer
C pointerC pointer
C pointer
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
C Pointers
C PointersC Pointers
C Pointers
 
Human values & professional ethics
Human values & professional ethicsHuman values & professional ethics
Human values & professional ethics
 

Similar to Advanced+pointers

C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programmingvipulkondekar
 
C Programming Language
C Programming LanguageC Programming Language
C Programming LanguageRTS Tech
 
C introduction
C introductionC introduction
C introductionMadhuriPareek
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentationnadim akber
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 
Lesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticLesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticPVS-Studio
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
C tutorials
C tutorialsC tutorials
C tutorialsAmit Kapoor
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Csdfsadf
CsdfsadfCsdfsadf
CsdfsadfAtul Setu
 

Similar to Advanced+pointers (20)

Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programming
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
C introduction
C introductionC introduction
C introduction
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
Lesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticLesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmetic
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 

Recently uploaded

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
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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
 
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
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...Pooja Nehwal
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

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
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
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
 
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
 
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...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Advanced+pointers

  • 1.
  • 2.
  • 3.
  • 4. Void Pointers CS 3090: Safety Critical Programming in C
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. CS 3090: Safety Critical Programming in C
  • 13. A C programmer cannot not decides what will be the memory address of any variables.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. CS 3090: Safety Critical Programming in C
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. 09/27/11 CS 3090: Safety Critical Programming in C
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. #include<stdio.h> int main(int argc, char *argv[]) { printf(&quot;No. of Argument::%d&quot;,argc); int cnt=argc-1; while(cnt>=1) { printf(&quot;Entered numbers are%s&quot;,argv[cnt]); cnt--; }return 0;}
  • 33.
  • 34. typedef struct IntNode { int value; struct IntNode *next; } INTNODE; INTNODE *search_list(INTNODE *node, int const key) { while (!node) { if (node->value == key) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C OK, but it only works for nodes containing integer data. If you want a list of strings, you’ll need to define a new type and new function.
  • 35. typedef struct Node { void *value; struct Node *next; } NODE; void construct_node(NODE *node, void *value, NODE *next) { node->value = value; node->next = next; } NODE *new_node(void *value, NODE *next) { NODE *node = (NODE *)malloc(sizeof(NODE)); construct_node(node, value, next); return node; } CS 3090: Safety Critical Programming in C void* is compatible with any pointer type. So, this member can hold (a pointer to) any value!
  • 36.
  • 37. NODE *search_list(NODE *node, void const *key, int (*compare)(void const *, void const *)) { while (node) { if (!compare(node->value, key)) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C Assumption: compare returns zero if its parameter values are equal; nonzero otherwise
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. int main(int argc, char **argv) { char id[ID_LIMIT]; switch(argc) { case 1: generate_ID(id); break; case 3: if (strcmp(argv[1], &quot;-i&quot;) exit(INVALID_ARG); strcpy(id, argv[2]); break; default: exit(INVALID_ARG_COUNT); } register(id); } CS 3090: Safety Critical Programming in C
  • 46.