SlideShare a Scribd company logo
1 of 25
C Programming
Essentials
Unit 1: Sequential Programming
CHAPTER 1: INTRODUCTION
DR. ERIC CHOU IEEE SENIOR MEMBER
IntroductionLECTURE 1
About This Course
Instructor: Dr. Eric Chou
Textbook:
The C Programming Language
by Kernighan, Ritchie. Second Edition
Topics
•Introduction to Programming in C
•Data Type, Operators, Basic I/O
•Conditional Expressions, Control Flow
•Loops
•Functions, Program Structure and Recursion
•Pointer and Arrays
•Structure, Union and Enum
•Dynamic allocation
•Storage Classes
•Pre-processor, File Handling, Exceptions, Math library
•Basic Algorithms: Searching, Sorting
Standard C
•Standardized in 1989 by ANSI (American National Standards Institute) known as
ANSI C
•International standard (ISO) in 1990 which was adopted by ANSI and is known
as C89
•As part of the normal evolution process the standard was updated in 1995
(C95) and 1999 (C99)
•C++ and C
• C++ extends C to include support for Object Oriented Programming and
other features that facilitate large software development projects
• C is not strictly a subset of C++, but it is possible to write “Clean C” that
conforms to both the C++ and C standards.
Elements of a C Program
•A C development environment includes
• System libraries and headers: a set of standard libraries and their header files. For example see
/usr/include and glibc.
• Application Source: application source and header files
• Compiler: converts source to object code for a specific platform
• Linker: resolves external references and produces the executable module
•User program structure
• there must be one main function where execution begins when the program is run. This function
is called main
• int main (void) { ... },
• int main (int argc, char *argv[]) { ... }
• UNIX Systems have a 3rd way to define main(), though it is not POSIX.1 compliant
int main (int argc, char *argv[], char *envp[])
• additional local and external functions and variables
About C
•GNU : GNU's Not Unix, We use MinGW version of gcc.
• GNU C: gcc is a standard compiler
•C is non-portable (Suitable for machine-native code development)
• Terms: Compiler (human -> machine [once]), Interpreter
(instructions -> machine [each time the program is run])
•C is a high level language
• One line in c maps to many lines of assembly code
Programming on Windows
DOS command line: GNU-C
• Text based editors: Notepad++
• MS-DOS/Window command line script
IDE
• Code::Blocks
http://www.codeblocks.org/
• Eclipse
https://eclipse.org/cdt/
My First C Program in
DOS Command Line
Compilation
LECTURE 2
My first C program!
/* thou shalt begin from somewhere*/
#include <stdio.h>
// program prints hello world
int main() {
printf ("Hello world!n");
return 0;
}
Files, directories and
permissions
Directory
drwxr-xr-x 2 echou cse 4096 2008-08-13 22:46 Pictures
File
-rw-r--r-- 1 echou cse 3446 2008-08-14 15:16 test.c
Special files (advanced)
• .a : static library
• .so : shared object code (dynamic)
• .o : object code
• Pipes : fifo / buffered prwx--x--x
• Device files : /dev/cdrom etc.
Programming on Windows
Writing programs
◦ Use any editor (graphical, console)
◦ Save file as <filename>.c
Compiling programs
◦ gcc <filename>.c gcc myfirst.c –o myfirst
Running programs
◦ ./a.out ./myfirst
(executable files need to have executable permissions.
$chmod +x <executable>) // for linux
Demo Program: myfirst.c
Go DOS Command!!!
My first C Program in
DOS Command Line
Compilation
LECTURE 3
Good
Programming
Practices
Variables names
• Not too short, not too long
• Always start variable names with small letters
• On work break
• Capitalize: myVariable, OR
• Separate: my_variable, OR
• Lower Case: myvariable
Rules for naming a variable
in C
•Only letters, digits and underscore_
•Start with letters or underscore only “[a-zA-Z_]”
•Case-sensitive
•No reserved words, no keywords, no known library
file name or variable names.
•There is no rule on how long a variable can be.
However, only the first 31 characters of a variable
are checked by the compiler. So, the first 31 letters
of two variables in a program should be different.
C is a strongly typed language. What this means it
that, the type of a variable cannot be changed.
Good Programming
Practices
Put comments
#include <stdio.h>
int main() {
/* this program adds
two numbers */
int a = 4; //first number
int b = 5; //second number
int res = 0; //result
res = a + b;
printf("%d + %d = %dn", a, b, res);
return 0;
}
A Simple C Program with Comments
/* Comment Block */
// comment line
•begin with /* and end with */ indicating that these two lines are a
comment.
•You insert comments to document programs and improve program
readability.
•Comments do not cause the computer to perform any action when
the program is run.
Good
Programming
Practices
•Your code may be used by somebody else
•The code may be long
•Should be easy to understand for you and for
others
•Saves lot of errors and makes debugging easier
•Speeds up program development
•Put code of a certain functionality (module) in a
file.
Code::Blocks Project
Building
LECTURE 4
Code::Blocks
Project Building
Build Build a Project
Create Create a New File
Program Program Arguments
Build Build Options
Project Project Properties
Create Create a new project (Empty Project)
Demo: Create myfirst in Code::Blocks
Go Code::Blocks!!!

More Related Content

What's hot

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingManoj Tyagi
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Shujaat Abbas
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin Kumar
 
C programming language
C programming languageC programming language
C programming languageMaha lakshmi
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRokonuzzaman Rony
 
introduction to c programming language
introduction to c programming languageintroduction to c programming language
introduction to c programming languagesanjay joshi
 
C programming basics
C  programming basicsC  programming basics
C programming basicsargusacademy
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
introduction to C programming (C)
introduction to C programming (C)introduction to C programming (C)
introduction to C programming (C)Abhishek Walia
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRutvik Pensionwar
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSivant Kolhe
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1Rumman Ansari
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming languagesanjay joshi
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilZenith SVG
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C LanguageMohamed Elsayed
 

What's hot (20)

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
 
Sachin kumar ppt on programming in c
Sachin kumar ppt on programming in cSachin kumar ppt on programming in c
Sachin kumar ppt on programming in c
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
C programming language
C programming languageC programming language
C programming language
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
introduction to c programming language
introduction to c programming languageintroduction to c programming language
introduction to c programming language
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
C programming basics
C  programming basicsC  programming basics
C programming basics
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
introduction to C programming (C)
introduction to C programming (C)introduction to C programming (C)
introduction to C programming (C)
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
 
C Programming - Refresher - Part I
C Programming - Refresher - Part I C Programming - Refresher - Part I
C Programming - Refresher - Part I
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakil
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 

Similar to Chapter 1: Introduction

Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptANISHYAPIT
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxsaivasu4
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++Vaibhav Khanna
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdfKalighatOkira
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge imtiazalijoono
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptxMangala R
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdfRajb54
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii pptJStalinAsstProfessor
 

Similar to Chapter 1: Introduction (20)

C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
C session 1.pptx
C session 1.pptxC session 1.pptx
C session 1.pptx
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
C programming
C programmingC programming
C programming
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 

Recently uploaded

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
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
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 

Recently uploaded (20)

Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
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
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 

Chapter 1: Introduction

  • 1. C Programming Essentials Unit 1: Sequential Programming CHAPTER 1: INTRODUCTION DR. ERIC CHOU IEEE SENIOR MEMBER
  • 3. About This Course Instructor: Dr. Eric Chou Textbook: The C Programming Language by Kernighan, Ritchie. Second Edition
  • 4. Topics •Introduction to Programming in C •Data Type, Operators, Basic I/O •Conditional Expressions, Control Flow •Loops •Functions, Program Structure and Recursion •Pointer and Arrays •Structure, Union and Enum •Dynamic allocation •Storage Classes •Pre-processor, File Handling, Exceptions, Math library •Basic Algorithms: Searching, Sorting
  • 5. Standard C •Standardized in 1989 by ANSI (American National Standards Institute) known as ANSI C •International standard (ISO) in 1990 which was adopted by ANSI and is known as C89 •As part of the normal evolution process the standard was updated in 1995 (C95) and 1999 (C99) •C++ and C • C++ extends C to include support for Object Oriented Programming and other features that facilitate large software development projects • C is not strictly a subset of C++, but it is possible to write “Clean C” that conforms to both the C++ and C standards.
  • 6.
  • 7.
  • 8. Elements of a C Program •A C development environment includes • System libraries and headers: a set of standard libraries and their header files. For example see /usr/include and glibc. • Application Source: application source and header files • Compiler: converts source to object code for a specific platform • Linker: resolves external references and produces the executable module •User program structure • there must be one main function where execution begins when the program is run. This function is called main • int main (void) { ... }, • int main (int argc, char *argv[]) { ... } • UNIX Systems have a 3rd way to define main(), though it is not POSIX.1 compliant int main (int argc, char *argv[], char *envp[]) • additional local and external functions and variables
  • 9. About C •GNU : GNU's Not Unix, We use MinGW version of gcc. • GNU C: gcc is a standard compiler •C is non-portable (Suitable for machine-native code development) • Terms: Compiler (human -> machine [once]), Interpreter (instructions -> machine [each time the program is run]) •C is a high level language • One line in c maps to many lines of assembly code
  • 10. Programming on Windows DOS command line: GNU-C • Text based editors: Notepad++ • MS-DOS/Window command line script IDE • Code::Blocks http://www.codeblocks.org/ • Eclipse https://eclipse.org/cdt/
  • 11. My First C Program in DOS Command Line Compilation LECTURE 2
  • 12. My first C program! /* thou shalt begin from somewhere*/ #include <stdio.h> // program prints hello world int main() { printf ("Hello world!n"); return 0; }
  • 13.
  • 14. Files, directories and permissions Directory drwxr-xr-x 2 echou cse 4096 2008-08-13 22:46 Pictures File -rw-r--r-- 1 echou cse 3446 2008-08-14 15:16 test.c Special files (advanced) • .a : static library • .so : shared object code (dynamic) • .o : object code • Pipes : fifo / buffered prwx--x--x • Device files : /dev/cdrom etc.
  • 15. Programming on Windows Writing programs ◦ Use any editor (graphical, console) ◦ Save file as <filename>.c Compiling programs ◦ gcc <filename>.c gcc myfirst.c –o myfirst Running programs ◦ ./a.out ./myfirst (executable files need to have executable permissions. $chmod +x <executable>) // for linux
  • 16. Demo Program: myfirst.c Go DOS Command!!!
  • 17. My first C Program in DOS Command Line Compilation LECTURE 3
  • 18. Good Programming Practices Variables names • Not too short, not too long • Always start variable names with small letters • On work break • Capitalize: myVariable, OR • Separate: my_variable, OR • Lower Case: myvariable
  • 19. Rules for naming a variable in C •Only letters, digits and underscore_ •Start with letters or underscore only “[a-zA-Z_]” •Case-sensitive •No reserved words, no keywords, no known library file name or variable names. •There is no rule on how long a variable can be. However, only the first 31 characters of a variable are checked by the compiler. So, the first 31 letters of two variables in a program should be different. C is a strongly typed language. What this means it that, the type of a variable cannot be changed.
  • 20. Good Programming Practices Put comments #include <stdio.h> int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int res = 0; //result res = a + b; printf("%d + %d = %dn", a, b, res); return 0; }
  • 21. A Simple C Program with Comments /* Comment Block */ // comment line •begin with /* and end with */ indicating that these two lines are a comment. •You insert comments to document programs and improve program readability. •Comments do not cause the computer to perform any action when the program is run.
  • 22. Good Programming Practices •Your code may be used by somebody else •The code may be long •Should be easy to understand for you and for others •Saves lot of errors and makes debugging easier •Speeds up program development •Put code of a certain functionality (module) in a file.
  • 24. Code::Blocks Project Building Build Build a Project Create Create a New File Program Program Arguments Build Build Options Project Project Properties Create Create a new project (Empty Project)
  • 25. Demo: Create myfirst in Code::Blocks Go Code::Blocks!!!