SlideShare a Scribd company logo
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.
Chapter 1: Introduction
Chapter 1: Introduction
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;
}
Chapter 1: Introduction
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

PPT
Why C is Called Structured Programming Language
Sinbad Konick
 
PPTX
Introduction to c programming
Alpana Gupta
 
PPTX
An Overview of Programming C
Nishargo Nigar
 
PPT
C PROGRAMMING
Stalongiles Philip
 
PPT
Brief introduction to the c programming language
Kumar Gaurav
 
PPTX
introduction to c language
Rai University
 
PDF
Introduction to c programming
Akshay Ithape
 
PPTX
Introduction to C programming
MalikaJoya
 
Why C is Called Structured Programming Language
Sinbad Konick
 
Introduction to c programming
Alpana Gupta
 
An Overview of Programming C
Nishargo Nigar
 
C PROGRAMMING
Stalongiles Philip
 
Brief introduction to the c programming language
Kumar Gaurav
 
introduction to c language
Rai University
 
Introduction to c programming
Akshay Ithape
 
Introduction to C programming
MalikaJoya
 

What's hot (20)

PPTX
Introduction to c programming
Manoj Tyagi
 
PPTX
Introduction to C Language (By: Shujaat Abbas)
Shujaat Abbas
 
PPTX
Sachin kumar ppt on programming in c
Sachin Kumar
 
PPTX
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
PPTX
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
PPTX
C programming language
Maha lakshmi
 
PPTX
Introduction to C programming
Rokonuzzaman Rony
 
PPTX
introduction to c programming language
sanjay joshi
 
PPTX
C Programming Language
Gitanshu Gitanshu
 
PPSX
C programming basics
argusacademy
 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
 
PPT
introduction to C programming (C)
Abhishek Walia
 
PPTX
Introduction to C programming
Rutvik Pensionwar
 
PPTX
Introduction to c programming
Sivant Kolhe
 
PPTX
C Programming Language Step by Step Part 1
Rumman Ansari
 
PDF
C Programming - Refresher - Part I
Emertxe Information Technologies Pvt Ltd
 
PPTX
Introduction to c programming language
sanjay joshi
 
PPTX
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
PPTX
A brief introduction to C Language
Mohamed Elsayed
 
Introduction to c programming
Manoj Tyagi
 
Introduction to C Language (By: Shujaat Abbas)
Shujaat Abbas
 
Sachin kumar ppt on programming in c
Sachin Kumar
 
C_Programming_Notes_ICE
Gilbert NZABONITEGEKA
 
C programming language
Maha lakshmi
 
Introduction to C programming
Rokonuzzaman Rony
 
introduction to c programming language
sanjay joshi
 
C Programming Language
Gitanshu Gitanshu
 
C programming basics
argusacademy
 
Introduction to C Programming
MOHAMAD NOH AHMAD
 
introduction to C programming (C)
Abhishek Walia
 
Introduction to C programming
Rutvik Pensionwar
 
Introduction to c programming
Sivant Kolhe
 
C Programming Language Step by Step Part 1
Rumman Ansari
 
C Programming - Refresher - Part I
Emertxe Information Technologies Pvt Ltd
 
Introduction to c programming language
sanjay joshi
 
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
A brief introduction to C Language
Mohamed Elsayed
 
Ad

Similar to Chapter 1: Introduction (20)

PDF
Introduction to C programming
Kathmandu University
 
PPTX
Aniket tore
anikettore1
 
PPT
history of c.ppt
arpanabharani
 
PDF
88 c-programs
Leandro Schenone
 
PPTX
C Program basic concepts using c knoweledge
priankarr1
 
PPTX
unit2.pptx
sscprep9
 
PPTX
C programming Training in Ambala ! Batra Computer Centre
jatin batra
 
PDF
88 c programs 15184
Sumit Saini
 
PDF
88 c-programs
Minh Thắng Trần
 
PPTX
Best_of_438343817-A-PPT-on-C-language.pptx
nilaythakkar7
 
PPTX
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
PPTX
C language ppt
Ğäùråv Júñêjå
 
PDF
Introduction of c language
farishah
 
PPTX
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
DOCX
C language industrial training report
Raushan Pandey
 
PPT
C Language
Aakash Singh
 
PPT
Presentation 2.ppt
UdhayaKumar175069
 
PPT
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
PPTX
PROGRAMMING IN C - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
DOCX
Uniti classnotes
Sowri Rajan
 
Introduction to C programming
Kathmandu University
 
Aniket tore
anikettore1
 
history of c.ppt
arpanabharani
 
88 c-programs
Leandro Schenone
 
C Program basic concepts using c knoweledge
priankarr1
 
unit2.pptx
sscprep9
 
C programming Training in Ambala ! Batra Computer Centre
jatin batra
 
88 c programs 15184
Sumit Saini
 
88 c-programs
Minh Thắng Trần
 
Best_of_438343817-A-PPT-on-C-language.pptx
nilaythakkar7
 
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
C language ppt
Ğäùråv Júñêjå
 
Introduction of c language
farishah
 
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
C language industrial training report
Raushan Pandey
 
C Language
Aakash Singh
 
Presentation 2.ppt
UdhayaKumar175069
 
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
PROGRAMMING IN C - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Uniti classnotes
Sowri Rajan
 
Ad

Recently uploaded (20)

PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPTX
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 

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.
  • 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; }
  • 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!!!