SlideShare a Scribd company logo
Programming in C
A little history:
 1970’s
 Unix
 C, from BCPL (Thompson and Ritchie)
 C programming Language
 Widely used like the others: Fortran, Pascal
 Main form of language for system programming
 Available on any machine with C compiler and
library
Some Characteristics:
 Scope:
 Intended:

HPC, OS, general programming

Typically, long developing cycle

very platform dependent
 Not intended: web, scripting, data processing
 Features:
 Close interaction with system

Standard library (user-level only),

no other fancy stuff: networking, memory, graphics
 Extensive use of pointers
 Procedure (OOB) programming, strictly pass by value
Sample 1:
/* Hello World! */
#include <stdio.h>
int main()
{
printf(“Hello World!n”);
return 0;
}
Walk through:
 C program: hello.c
 emacs, vi, vim, pico, joe …
 But text editors only. No word processor
 Preprocessing: hello.s, assembly code
 cc -S hello.c
 Compilation: hello.o, a binary file
 cc -c hello.s
 Linking: a.out or hello, an executable file
 cc hello.o
 cc -o hello hello.o
 Loading (dynamical linking) and execution: ./hello
 ./a.out
 ./hello
Programming (Editing)
 C program: hello.c
 emacs, vi, vim, pico, joe …
 But text editors only. No word processor
Compile:
 Preprocessing: hello.s, assembly code
 cc -S hello.c
 Can you take a look at hello.s and compare to hello.c?
 Compilation: hello.o, a binary file
 cc -c hello.s
 Do you know how to take a look at hello.o?
 Linking: a.out or hello, an executable file
 cc hello.o
 cc -o hello hello.o
 Want to look at the executable, hello?
Run:
 Loading (dynamical linking) and execute: ./hello
 ./a.out
 ./hello
 What you do with java programs?
 What computer does to run your program?
Sample 1 Dissection:
 What it has?
 A function definition: main
 A line of comment
 A line of preprocessor directive
 An output statement
 A return clause
 What it does?
 Ask the computer to say hello to the world.
 What it does not do?
 It seems not computing!!
 No real work

not taking input

does not change any value
Sample 2:
#include <stdio.h>
#define MAGIC 10
int main(void)
{
int i, fact, quotient;
while (i++ < 3) {
printf(”Guess a factor of MAGIC larger than 1: ");
scanf("%d”, &fact);
quotient = MAGIC % fact;
if (0 == quotient)
printf(”You got it!n”);
else
printf(”Sorry, You missed it!n”);
}
return 0;
}
Sample 2 Dissection:
 What more it has?
 Macro definition
 Variable declaration
 Operations represented by operators
 Conditional computation
 Input Processing
 Loops: three chances
Syntax Dissection:
 What is syntax?
 m-w.com:

the way in which linguistic elements (as words) are put together
to form constituents (as phrases or clauses)
 How to put your C elements together into a program?
 Variable declaration,
 Identifier: case, keywords, style
 datatype specification

char, short, int, long, float, double
 Operators:
 +, -, *, /, %, ++, --; >, <, ==, ; &, |, …
 Priority and Precedence
 Associativity
More Syntax Dissection:
 Preprocessor directive
 macro
 header file inclusion
 Loop constructs
 for, while, do-while, break, continue, label--go;
 Conditional statements
 If, else, else if, switch, break
 Function definition
 return type, parameter definition, parameter passing
 Standard library and function calls
 Take home practice:
 Walk through the following steps with sample 2

preprocessing, compilation, linking, loading/execute

Modify and repeat once more if you can

More Related Content

PDF
15CS664 Python Question Bank-3
Syed Mustafa
 
PDF
pyton Notes1
Amba Research
 
PDF
Differences between c and c++
starlit electronics
 
PDF
Highlevel assemly
karishmamubeen
 
PPTX
Let's talks about string operations in C++17
Bartlomiej Filipek
 
PDF
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Bartlomiej Filipek
 
PPT
Go lang introduction
yangwm
 
PDF
What comments hide
PVS-Studio
 
15CS664 Python Question Bank-3
Syed Mustafa
 
pyton Notes1
Amba Research
 
Differences between c and c++
starlit electronics
 
Highlevel assemly
karishmamubeen
 
Let's talks about string operations in C++17
Bartlomiej Filipek
 
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Bartlomiej Filipek
 
Go lang introduction
yangwm
 
What comments hide
PVS-Studio
 

What's hot (20)

PPTX
Go Programming Language (Golang)
Ishin Vin
 
PPTX
Chapter 1: Introduction
Eric Chou
 
PPTX
C++ language
Elizabeth Pisarek
 
PPTX
Vocabulary Types in C++17
Bartlomiej Filipek
 
PDF
To GO or not to GO
superstas88
 
PPTX
C++17 std::filesystem - Overview
Bartlomiej Filipek
 
PDF
A Tour of Go - Workshop
Rodolfo Carvalho
 
PDF
The GNOME way - What can we learn from and within the Open Documentation World
Radina Matic
 
PPT
Introduction to Go programming
Exotel
 
PPTX
Python vs c++ ppt
AllProgrammingHelp
 
PPTX
introduction to c programming language
sanjay joshi
 
PDF
Retour sur la Microsoft //Build 2018
Timothé Larivière
 
PDF
10 reasons to be excited about go
Dvir Volk
 
PPTX
difference between c c++ c#
Sireesh K
 
PDF
Core Java Meetup #9 - Quiz Questions - 6th May
CodeOps Technologies LLP
 
PDF
Introduction to Go language
Tzar Umang
 
PDF
Introduction to go language programming
Mahmoud Masih Tehrani
 
PDF
C++ vs python the best ever comparison
calltutors
 
ODP
C# and the Evolution of a Programming Language
Jacinto Limjap
 
PDF
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
Kamiya Toshihiro
 
Go Programming Language (Golang)
Ishin Vin
 
Chapter 1: Introduction
Eric Chou
 
C++ language
Elizabeth Pisarek
 
Vocabulary Types in C++17
Bartlomiej Filipek
 
To GO or not to GO
superstas88
 
C++17 std::filesystem - Overview
Bartlomiej Filipek
 
A Tour of Go - Workshop
Rodolfo Carvalho
 
The GNOME way - What can we learn from and within the Open Documentation World
Radina Matic
 
Introduction to Go programming
Exotel
 
Python vs c++ ppt
AllProgrammingHelp
 
introduction to c programming language
sanjay joshi
 
Retour sur la Microsoft //Build 2018
Timothé Larivière
 
10 reasons to be excited about go
Dvir Volk
 
difference between c c++ c#
Sireesh K
 
Core Java Meetup #9 - Quiz Questions - 6th May
CodeOps Technologies LLP
 
Introduction to Go language
Tzar Umang
 
Introduction to go language programming
Mahmoud Masih Tehrani
 
C++ vs python the best ever comparison
calltutors
 
C# and the Evolution of a Programming Language
Jacinto Limjap
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
Kamiya Toshihiro
 
Ad

Viewers also liked (20)

DOCX
C programming tutorial
Mohit Saini
 
PPTX
Switch case and looping statement
_jenica
 
PPSX
Break and continue
Frijo Francis
 
PPSX
C lecture 3 control statements slideshare
Gagan Deep
 
PPTX
Selection statements
Harsh Dabas
 
PPSX
Break and continue statement in C
Innovative
 
PPTX
Conditional Statement in C Language
Shaina Arora
 
DOC
Jumping statements
Suneel Dogra
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PPTX
C decision making and looping.
Haard Shah
 
PPTX
Switch case and looping
patricia Hidalgo
 
PPT
Ch3 selection
Hattori Sidek
 
PDF
C Prog. - Decision & Loop Controls
vinay arora
 
PPT
Ch3 repetition
Hattori Sidek
 
PPTX
Loops Basics
Mushiii
 
PPTX
Loops
Peter Andrews
 
PPTX
Looping statements in C
Jeya Lakshmi
 
C programming tutorial
Mohit Saini
 
Switch case and looping statement
_jenica
 
Break and continue
Frijo Francis
 
C lecture 3 control statements slideshare
Gagan Deep
 
Selection statements
Harsh Dabas
 
Break and continue statement in C
Innovative
 
Conditional Statement in C Language
Shaina Arora
 
Jumping statements
Suneel Dogra
 
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
C decision making and looping.
Haard Shah
 
Switch case and looping
patricia Hidalgo
 
Ch3 selection
Hattori Sidek
 
C Prog. - Decision & Loop Controls
vinay arora
 
Ch3 repetition
Hattori Sidek
 
Loops Basics
Mushiii
 
Looping statements in C
Jeya Lakshmi
 
Ad

Similar to C Lecture (20)

PPTX
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
PPTX
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
PPTX
chapter 1.pptx
SeethaDinesh
 
PPTX
C Programming UNIT 1.pptx
Mugilvannan11
 
PDF
Introduction to C Programming | Importance of Learning C
ShehanNadeesha
 
PDF
Introduction to C programming
Kathmandu University
 
DOC
Basic c
Veera Karthi
 
DOCX
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
PDF
67404923-C-Programming-Tutorials-Doc.pdf
Rajb54
 
PPTX
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
PDF
Introduction of c language
farishah
 
PPTX
C Programming Lecture 2 - Structure of a C Program.pptx
Murali M
 
PPT
8844632.ppt
SushmaG48
 
PDF
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
 
PPTX
Mca i pic u-1 introduction to c language
Rai University
 
PDF
C Language
Syed Zaid Irshad
 
PPT
C_Intro.ppt
gitesh_nagar
 
PPTX
2.Overview of C language.pptx
Vishwas459764
 
PPTX
Overview of c
Chandrapriya Rediex
 
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
chapter 1.pptx
SeethaDinesh
 
C Programming UNIT 1.pptx
Mugilvannan11
 
Introduction to C Programming | Importance of Learning C
ShehanNadeesha
 
Introduction to C programming
Kathmandu University
 
Basic c
Veera Karthi
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
67404923-C-Programming-Tutorials-Doc.pdf
Rajb54
 
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
Introduction of c language
farishah
 
C Programming Lecture 2 - Structure of a C Program.pptx
Murali M
 
8844632.ppt
SushmaG48
 
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
 
Mca i pic u-1 introduction to c language
Rai University
 
C Language
Syed Zaid Irshad
 
C_Intro.ppt
gitesh_nagar
 
2.Overview of C language.pptx
Vishwas459764
 
Overview of c
Chandrapriya Rediex
 

More from Sudharsan S (20)

PPT
Xml1111
Sudharsan S
 
PPT
Xml11
Sudharsan S
 
PPT
Xml plymouth
Sudharsan S
 
PPT
Xml Presentation-3
Sudharsan S
 
PPT
Xml Presentation-1
Sudharsan S
 
PPT
XML Presentation-2
Sudharsan S
 
PPT
Xml
Sudharsan S
 
PPT
Unix Shell Scripting Basics
Sudharsan S
 
PPT
Unix
Sudharsan S
 
PPT
Introduction to Unix
Sudharsan S
 
PDF
Unix
Sudharsan S
 
PPT
C Tutorials
Sudharsan S
 
PPT
C Introduction
Sudharsan S
 
PDF
College1
Sudharsan S
 
PDF
C Programming
Sudharsan S
 
PDF
C Tutorials
Sudharsan S
 
PPT
Preface
Sudharsan S
 
PPT
Toc Sg
Sudharsan S
 
PPT
Les08
Sudharsan S
 
PPT
Les06
Sudharsan S
 
Xml1111
Sudharsan S
 
Xml plymouth
Sudharsan S
 
Xml Presentation-3
Sudharsan S
 
Xml Presentation-1
Sudharsan S
 
XML Presentation-2
Sudharsan S
 
Unix Shell Scripting Basics
Sudharsan S
 
Introduction to Unix
Sudharsan S
 
C Tutorials
Sudharsan S
 
C Introduction
Sudharsan S
 
College1
Sudharsan S
 
C Programming
Sudharsan S
 
C Tutorials
Sudharsan S
 
Preface
Sudharsan S
 
Toc Sg
Sudharsan S
 

Recently uploaded (20)

PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
CDH. pptx
AneetaSharma15
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Trends in pediatric nursing .pptx
AneetaSharma15
 

C Lecture

  • 2. A little history:  1970’s  Unix  C, from BCPL (Thompson and Ritchie)  C programming Language  Widely used like the others: Fortran, Pascal  Main form of language for system programming  Available on any machine with C compiler and library
  • 3. Some Characteristics:  Scope:  Intended:  HPC, OS, general programming  Typically, long developing cycle  very platform dependent  Not intended: web, scripting, data processing  Features:  Close interaction with system  Standard library (user-level only),  no other fancy stuff: networking, memory, graphics  Extensive use of pointers  Procedure (OOB) programming, strictly pass by value
  • 4. Sample 1: /* Hello World! */ #include <stdio.h> int main() { printf(“Hello World!n”); return 0; }
  • 5. Walk through:  C program: hello.c  emacs, vi, vim, pico, joe …  But text editors only. No word processor  Preprocessing: hello.s, assembly code  cc -S hello.c  Compilation: hello.o, a binary file  cc -c hello.s  Linking: a.out or hello, an executable file  cc hello.o  cc -o hello hello.o  Loading (dynamical linking) and execution: ./hello  ./a.out  ./hello
  • 6. Programming (Editing)  C program: hello.c  emacs, vi, vim, pico, joe …  But text editors only. No word processor
  • 7. Compile:  Preprocessing: hello.s, assembly code  cc -S hello.c  Can you take a look at hello.s and compare to hello.c?  Compilation: hello.o, a binary file  cc -c hello.s  Do you know how to take a look at hello.o?  Linking: a.out or hello, an executable file  cc hello.o  cc -o hello hello.o  Want to look at the executable, hello?
  • 8. Run:  Loading (dynamical linking) and execute: ./hello  ./a.out  ./hello  What you do with java programs?  What computer does to run your program?
  • 9. Sample 1 Dissection:  What it has?  A function definition: main  A line of comment  A line of preprocessor directive  An output statement  A return clause  What it does?  Ask the computer to say hello to the world.  What it does not do?  It seems not computing!!  No real work  not taking input  does not change any value
  • 10. Sample 2: #include <stdio.h> #define MAGIC 10 int main(void) { int i, fact, quotient; while (i++ < 3) { printf(”Guess a factor of MAGIC larger than 1: "); scanf("%d”, &fact); quotient = MAGIC % fact; if (0 == quotient) printf(”You got it!n”); else printf(”Sorry, You missed it!n”); } return 0; }
  • 11. Sample 2 Dissection:  What more it has?  Macro definition  Variable declaration  Operations represented by operators  Conditional computation  Input Processing  Loops: three chances
  • 12. Syntax Dissection:  What is syntax?  m-w.com:  the way in which linguistic elements (as words) are put together to form constituents (as phrases or clauses)  How to put your C elements together into a program?  Variable declaration,  Identifier: case, keywords, style  datatype specification  char, short, int, long, float, double  Operators:  +, -, *, /, %, ++, --; >, <, ==, ; &, |, …  Priority and Precedence  Associativity
  • 13. More Syntax Dissection:  Preprocessor directive  macro  header file inclusion  Loop constructs  for, while, do-while, break, continue, label--go;  Conditional statements  If, else, else if, switch, break  Function definition  return type, parameter definition, parameter passing  Standard library and function calls  Take home practice:  Walk through the following steps with sample 2  preprocessing, compilation, linking, loading/execute  Modify and repeat once more if you can

Editor's Notes

  • #4: My bias: C is hard and it is fun it embodies the most engineering art of programming