SlideShare uma empresa Scribd logo
1 de 65
The C Language Prof. Stephen A. Edwards
The C Language ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C History ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BCPL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C History ,[object Object],[object Object],[object Object],[object Object]
C History ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hello World in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hello World in C ,[object Object],[object Object],[object Object],[object Object],[object Object],Program mostly a collection of functions “ main” function special: the entry point “ void” qualifier indicates function does not return anything I/O performed by a library function: not included in the language
Euclid’s algorithm in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],“ New Style” function declaration lists number and type of arguments Originally only listed return type. Generated code did not care how many arguments were actually passed. Arguments are call-by-value
Euclid’s algorithm in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Automatic variable Storage allocated on stack when function entered, released when it returns. All parameters, automatic variables accessed w.r.t. frame pointer. Extra storage needed while evaluating large expressions also placed on the stack n m ret. addr. r Frame pointer Stack pointer Excess arguments simply ignored
Euclid’s algorithm in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Expression: C’s basic type of statement. Arithmetic and logical Assignment (=) returns a value, so can be used in expressions % is remainder != is not equal
Euclid’s algorithm in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],High-level control-flow statement. Ultimately becomes a conditional branch. Supports “structured programming” Each function returns a single value, usually an integer. Returned through a specific register by convention.
Euclid Compiled on PDP-11 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],int gcd(int m, int n) { int r; while ( (r = m % n) != 0) { m = n; n = r; } return n; }
Euclid Compiled on PDP-11 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Very natural mapping from C into PDP-11 instructions. Complex addressing modes make frame-pointer-relative accesses easy. Another idiosyncrasy: registers were memory-mapped, so taking address of a variable in a register is straightforward.
Pieces of C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Type Examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Integer j: pointer to integer, int k ch: pointer to unsigned char Array of 10 floats 2-arg function Array of three arrays of five … function returning int * pointer to function returning int
C Typedef ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Struct bit-fields ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Unions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Alignment of data in structs ,[object Object],[object Object],[object Object],[object Object],4 3 2 1 4 3 2 1
Alignment of data in structs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a b b b b c a b b b b c Pad
C Storage Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Linker-visible. Allocated at fixed location Visible within file. Allocated at fixed location. Visible within func. Allocated at fixed location.
C Storage Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Space allocated on stack by function. Space allocated on stack by caller. Space allocated on heap by library routine.
malloc() and free() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
malloc() and free() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
malloc() and free() ,[object Object],[object Object],[object Object],[object Object]
Dynamic Storage Allocation ,[object Object],[object Object],Free malloc( )
Dynamic Storage Allocation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dynamic Storage Allocation ,[object Object],[object Object],[object Object],[object Object]
Simple Dynamic Storage Allocation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple Dynamic Storage Allocation Next Size Next Size Size Free block Allocated block malloc( ) First large-enough free block selected Free block divided into two Previous next pointer updated Newly-allocated region begins with a size value
Simple Dynamic Storage Allocation free(a) Appropriate position in free list identified Newly-freed region added to adjacent free regions
Dynamic Storage Allocation ,[object Object],[object Object],[object Object],[object Object],[object Object]
Memory Pools ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Arrays ,[object Object],[object Object],Filippo Brunelleschi, Ospdale degli Innocenti, Firenze, Italy, 1421 ,[object Object],[object Object],[object Object],[object Object]
Multidimensional Arrays ,[object Object],[object Object],[object Object],[object Object],2 2 2 3 2 2 2 3 2 2 2 3 ... 10 Seagram Building, Ludwig Mies van der Rohe,1957
Multidimensional Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object]
Multidimensional Arrays ,[object Object],[object Object],[object Object],[object Object],The value int ** int * int int ***a
C Expressions ,[object Object],[object Object],[object Object],[object Object]
C Expression Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bitwise operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Lazy Logical Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],                                                                                                                      
Conditional Operator ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Side-effects in expressions ,[object Object],[object Object],[object Object],[object Object]
Pointer Arithmetic ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Switch Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],tmp = expr; if (tmp == 1) goto L1 else if (tmp == 5) goto L5 else if (tmp == 6) goto L6 else goto Default; L1: … goto Break; L5:; L6: … goto Break; Default: … goto Break; Break:
Switch Generates Interesting Code ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
setjmp/longjmp ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Space for a return address and registers (including stack pointer, frame pointer) Stores context, returns 0 Returns to context, making it appear setjmp() returned 1
The Macro Preprocessor ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Macro Preprocessor Pitfalls ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Macro Preprocessor Pitfalls ,[object Object],[object Object],[object Object],[object Object],[object Object]
Macro Preprocessor pitfalls ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Macro Preprocessor Pitfalls ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nondeterminism in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nondeterminism in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nondeterminism in C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of C types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of C expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of C statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary of C ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Main Points ,[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
Dushmanta Nath
 

Mais procurados (20)

Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 
C basics
C   basicsC   basics
C basics
 
C Language
C LanguageC Language
C Language
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C language
C languageC language
C language
 
C programming language
C programming languageC programming language
C programming language
 

Destaque (6)

Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
 
Clanguage
ClanguageClanguage
Clanguage
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Array in c language
Array in c languageArray in c language
Array in c language
 
C language ppt
C language pptC language ppt
C language ppt
 

Semelhante a C language

Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
guest3eed30
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
Wei Lin
 

Semelhante a C language (20)

C language
C languageC language
C language
 
Theory1&2
Theory1&2Theory1&2
Theory1&2
 
Introduction to c language and its application.ppt
Introduction to c language and its application.pptIntroduction to c language and its application.ppt
Introduction to c language and its application.ppt
 
anjaan007
anjaan007anjaan007
anjaan007
 
C Programming language
C Programming languageC Programming language
C Programming language
 
Clanguage
ClanguageClanguage
Clanguage
 
Clanguage
ClanguageClanguage
Clanguage
 
Clanguage
ClanguageClanguage
Clanguage
 
Software Security
Software SecuritySoftware Security
Software Security
 
cp05.pptx
cp05.pptxcp05.pptx
cp05.pptx
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Declare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code GenerationDeclare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code Generation
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 

Último

{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
hyt3577
 

Último (20)

Transformative Leadership: N Chandrababu Naidu and TDP's Vision for Innovatio...
Transformative Leadership: N Chandrababu Naidu and TDP's Vision for Innovatio...Transformative Leadership: N Chandrababu Naidu and TDP's Vision for Innovatio...
Transformative Leadership: N Chandrababu Naidu and TDP's Vision for Innovatio...
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 46 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 46 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 46 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 46 (Gurgaon)
 
06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdf06052024_First India Newspaper Jaipur.pdf
06052024_First India Newspaper Jaipur.pdf
 
Gujarat-SEBCs.pdf pfpkoopapriorjfperjreie
Gujarat-SEBCs.pdf pfpkoopapriorjfperjreieGujarat-SEBCs.pdf pfpkoopapriorjfperjreie
Gujarat-SEBCs.pdf pfpkoopapriorjfperjreie
 
422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdf422524114-Patriarchy-Kamla-Bhasin gg.pdf
422524114-Patriarchy-Kamla-Bhasin gg.pdf
 
WhatsApp 📞 8448380779 ✅Call Girls In Chaura Sector 22 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Chaura Sector 22 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Chaura Sector 22 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Chaura Sector 22 ( Noida)
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 48 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 48 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 48 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 48 (Gurgaon)
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's DevelopmentNara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
 
Group_5_US-China Trade War to understand the trade
Group_5_US-China Trade War to understand the tradeGroup_5_US-China Trade War to understand the trade
Group_5_US-China Trade War to understand the trade
 
Politician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full DetailsPolitician uddhav thackeray biography- Full Details
Politician uddhav thackeray biography- Full Details
 
Busty Desi⚡Call Girls in Sector 62 Noida Escorts >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Sector 62 Noida Escorts >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Sector 62 Noida Escorts >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Sector 62 Noida Escorts >༒8448380779 Escort Service
 
04052024_First India Newspaper Jaipur.pdf
04052024_First India Newspaper Jaipur.pdf04052024_First India Newspaper Jaipur.pdf
04052024_First India Newspaper Jaipur.pdf
 
China's soft power in 21st century .pptx
China's soft power in 21st century   .pptxChina's soft power in 21st century   .pptx
China's soft power in 21st century .pptx
 
Embed-4.pdf lkdiinlajeklhndklheduhuekjdh
Embed-4.pdf lkdiinlajeklhndklheduhuekjdhEmbed-4.pdf lkdiinlajeklhndklheduhuekjdh
Embed-4.pdf lkdiinlajeklhndklheduhuekjdh
 
{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
{Qatar{^🚀^(+971558539980**}})Abortion Pills for Sale in Dubai. .abu dhabi, sh...
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 47 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 47 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 47 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 47 (Gurgaon)
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Palam Vihar (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Palam Vihar (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Palam Vihar (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Palam Vihar (Gurgaon)
 
America Is the Target; Israel Is the Front Line _ Andy Blumenthal _ The Blogs...
America Is the Target; Israel Is the Front Line _ Andy Blumenthal _ The Blogs...America Is the Target; Israel Is the Front Line _ Andy Blumenthal _ The Blogs...
America Is the Target; Israel Is the Front Line _ Andy Blumenthal _ The Blogs...
 
declarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdfdeclarationleaders_sd_re_greens_theleft_5.pdf
declarationleaders_sd_re_greens_theleft_5.pdf
 

C language

  • 1. The C Language Prof. Stephen A. Edwards
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Simple Dynamic Storage Allocation Next Size Next Size Size Free block Allocated block malloc( ) First large-enough free block selected Free block divided into two Previous next pointer updated Newly-allocated region begins with a size value
  • 34. Simple Dynamic Storage Allocation free(a) Appropriate position in free list identified Newly-freed region added to adjacent free regions
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.