SlideShare a Scribd company logo
CSE240 – Introduction to
Programming Languages
Lecture 06:
Programming with C
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2
Imperative Paradigm
Fully specified and fully controlled
manipulation of named data in a stepwise fashion.
which means that:
Programs are algorithmic in nature:
do this, then that, then repeat this ten times
Focuses on how rather than what.
variables
functions (methods in Java)
Loop statements
Conditional statements
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3
Paradigms
variables
functions (methods in Java)
Loop statements
Conditional statements
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4
Paradigms
variables
functions (methods in Java)
Loop statements
Conditional statements
// Different from
// Java
Arrays
Structs
Pointers
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5
Paradigms
variables
functions (methods in Java)
Loop statements
Conditional statements
/*There are NOT
classes
Classes and
Objects will
appear in C++
*/
// Different from
// Java
Array
Structures
Pointers
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6
Outline
1. Getting started with Language C
2. Primitive data types, arrays (and strings)
3. Pointers
4. typedef, enum and struct type
5. Functions calls and parameter passing
1. Getting Started
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8
We Need a Compiler
• Microsoft Visual Studio for C/C++
View instructions on Blackboard
• Online Compiler for C/C++
https://www.onlinegdb.com/online_c_compiler
• Dev-C++ 5
http://www.bloodshed.net/devcpp.html
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9
Reference
• Textbook
Section 2.1 to 2.5 and 2.7
Optional 2.6 (files), 2.7 (recursion). – not included in the exam
• The Programming Language C by Kernighan and Ritchie
https://archive.org/details/TheCProgrammingLanguageFirstEdition
• Learning C programming
https://www.tutorialspoint.com/cprogramming/cprogramming_tutorial.pdf
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10
Anatomy of a Program in C
• The parts (components) of a C program are called functions.
• There are built-in functions that exist in libraries and user defined
functions that are written by the programmers.
• You can declare variables inside and outside functions. They are
called local variables and global variables, respectively.
• And, a program in C must contain exactly one main( ) function.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11
Getting Started
1. Comments are identical in Java
2. #include is equivalent to import
3. Libraries are *.h files
4. There are not classes
5. Methods are called functions.
6. Global variables, local
variables, and parameters.
7. Most of the lexical, syntactical,
and semantical rules are as you
know from your Java courses
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12
main()
8. Like Java, main( ) is the entry point
for program execution.
But, (1) C allows void or int as
type for main; (2) C allows empty
parameters or two parameters for
main. This are correct:
• void main () {
}
• void main (int argc, char *argv [ ]) { }
• int main() {return 0;}
• main() {return 0;} // if there is not a
type, C apply as default int
• int main (int argc, char *argv [ ]) { }
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13
main()
8. Like Java, main( ) is the entry point
for program execution.
But, (1) C allows void or int as
type for main; (2) C allows empty
parameters or two parameters for
main. This are correct:
• void main () {
}
• void main (int argc, char *argv [ ]) { }
• int main() {return 0;}
• main() {return 0;} // if there is not a
type, C apply as default int
• int main (int argc, char *argv [ ]) { }
public static void main(String [] args) {
}
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 14
Output
printf (control sequence, expressions);
• The control sequence includes a
constant string to be printed, e.g.,
"Result: ", and control symbols to be
used to convert variables from their
numeric values that are stored in the
computer to printing format.
• The expressions is the list of
expressions whose values are to be
printed out. Each expression is
separated by a comma. This is
optional.
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 15
Output
printf (control sequence, expressions);
• The control sequence includes a
constant string to be printed, e.g.,
"Result: ", and control symbols to be
used to convert variables from their
numeric values that are stored in the
computer to printing format.
• The expressions is the list of
expressions whose values are to be
printed out. Each expression is
separated by a comma.
%d for integer
%f for floating point
%c for character
%s for string of characters
%p address
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 16
Output
printf (control sequence, expressions);
• The control sequence includes a
constant string to be printed, e.g.,
"Result: ", and control symbols to be
used to convert variables from their
numeric values that are stored in the
computer to printing format.
• The expressions is the list of
expressions whose values are to be
printed out. Each expression is
separated by a comma. This is
optional.
// Java
int x = 5;
float y = 10.3f;
System.out.println("hello " + x + " bye " + y);
// C
int x = 5;
float y = 10.3;
printf("hello %d bye %f", x, y);
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 17
#include <stdio.h>
void main () {
int i, n = 5;
printf("Hi, please enter an integer: ");
// input: scanf (control sequence, &variable1, ... &variablen);
// &variable: address of the variable.
scanf("%d", &i); // input function
if (i > n)
n = n + i;
else
n = n - i;
printf("i = %d, n = %dn", i, n); //output function
}
Input
Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 18
Control Statements
These that you know, work in the same way
• for, while, do/while
• if/else, switch
But, there are not boolean values. Zero is false and any other number is true.
The following program is correct and print “Hello”
CSE240 – Introduction to Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Fall 2017
Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.

More Related Content

What's hot

Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
C programming function
C  programming functionC  programming function
C programming function
argusacademy
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
Javier Gonzalez-Sanchez
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
Ahmad55ali
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
Digvijaysinh Gohil
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
LavanyaManokaran
 
Operators
OperatorsOperators
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
function in c
function in cfunction in c
function in c
subam3
 
C operators
C operatorsC operators
C operators
GPERI
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Programming in C
Programming in CProgramming in C
Programming in C
Nishant Munjal
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
imtiazalijoono
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
Prabhu Govind
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 

What's hot (20)

Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
C programming function
C  programming functionC  programming function
C programming function
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
201801 CSE240 Lecture 07
201801 CSE240 Lecture 07201801 CSE240 Lecture 07
201801 CSE240 Lecture 07
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
 
Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Operators
OperatorsOperators
Operators
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
function in c
function in cfunction in c
function in c
 
C operators
C operatorsC operators
C operators
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
What is c
What is cWhat is c
What is c
 
Function in c
Function in cFunction in c
Function in c
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 

Similar to 201801 CSE240 Lecture 06

C programming
C programmingC programming
C programming
PralhadKhanal1
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
vanshhans21102005
 
4th unit full
4th unit full4th unit full
4th unit full
Murali Saktheeswaran
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
Jadavsejal
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
Manivannan837728
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
RSathyaPriyaCSEKIOT
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
SURBHI SAROHA
 
C programming
C programmingC programming
C programming
Rounak Samdadia
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 

Similar to 201801 CSE240 Lecture 06 (20)

Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
C programming
C programmingC programming
C programming
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
4th unit full
4th unit full4th unit full
4th unit full
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C programming language
C programming languageC programming language
C programming language
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
 
Pc module1
Pc module1Pc module1
Pc module1
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
C programming
C programmingC programming
C programming
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 

More from Javier Gonzalez-Sanchez

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
Javier Gonzalez-Sanchez
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 

Recently uploaded

Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 

Recently uploaded (20)

Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 

201801 CSE240 Lecture 06

  • 1. CSE240 – Introduction to Programming Languages Lecture 06: Programming with C Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 2 Imperative Paradigm Fully specified and fully controlled manipulation of named data in a stepwise fashion. which means that: Programs are algorithmic in nature: do this, then that, then repeat this ten times Focuses on how rather than what. variables functions (methods in Java) Loop statements Conditional statements
  • 3. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 3 Paradigms variables functions (methods in Java) Loop statements Conditional statements
  • 4. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 4 Paradigms variables functions (methods in Java) Loop statements Conditional statements // Different from // Java Arrays Structs Pointers
  • 5. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 5 Paradigms variables functions (methods in Java) Loop statements Conditional statements /*There are NOT classes Classes and Objects will appear in C++ */ // Different from // Java Array Structures Pointers
  • 6. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 6 Outline 1. Getting started with Language C 2. Primitive data types, arrays (and strings) 3. Pointers 4. typedef, enum and struct type 5. Functions calls and parameter passing
  • 8. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 8 We Need a Compiler • Microsoft Visual Studio for C/C++ View instructions on Blackboard • Online Compiler for C/C++ https://www.onlinegdb.com/online_c_compiler • Dev-C++ 5 http://www.bloodshed.net/devcpp.html
  • 9. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 9 Reference • Textbook Section 2.1 to 2.5 and 2.7 Optional 2.6 (files), 2.7 (recursion). – not included in the exam • The Programming Language C by Kernighan and Ritchie https://archive.org/details/TheCProgrammingLanguageFirstEdition • Learning C programming https://www.tutorialspoint.com/cprogramming/cprogramming_tutorial.pdf
  • 10. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 10 Anatomy of a Program in C • The parts (components) of a C program are called functions. • There are built-in functions that exist in libraries and user defined functions that are written by the programmers. • You can declare variables inside and outside functions. They are called local variables and global variables, respectively. • And, a program in C must contain exactly one main( ) function.
  • 11. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 11 Getting Started 1. Comments are identical in Java 2. #include is equivalent to import 3. Libraries are *.h files 4. There are not classes 5. Methods are called functions. 6. Global variables, local variables, and parameters. 7. Most of the lexical, syntactical, and semantical rules are as you know from your Java courses
  • 12. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 12 main() 8. Like Java, main( ) is the entry point for program execution. But, (1) C allows void or int as type for main; (2) C allows empty parameters or two parameters for main. This are correct: • void main () { } • void main (int argc, char *argv [ ]) { } • int main() {return 0;} • main() {return 0;} // if there is not a type, C apply as default int • int main (int argc, char *argv [ ]) { }
  • 13. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 13 main() 8. Like Java, main( ) is the entry point for program execution. But, (1) C allows void or int as type for main; (2) C allows empty parameters or two parameters for main. This are correct: • void main () { } • void main (int argc, char *argv [ ]) { } • int main() {return 0;} • main() {return 0;} // if there is not a type, C apply as default int • int main (int argc, char *argv [ ]) { } public static void main(String [] args) { }
  • 14. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 14 Output printf (control sequence, expressions); • The control sequence includes a constant string to be printed, e.g., "Result: ", and control symbols to be used to convert variables from their numeric values that are stored in the computer to printing format. • The expressions is the list of expressions whose values are to be printed out. Each expression is separated by a comma. This is optional.
  • 15. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 15 Output printf (control sequence, expressions); • The control sequence includes a constant string to be printed, e.g., "Result: ", and control symbols to be used to convert variables from their numeric values that are stored in the computer to printing format. • The expressions is the list of expressions whose values are to be printed out. Each expression is separated by a comma. %d for integer %f for floating point %c for character %s for string of characters %p address
  • 16. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 16 Output printf (control sequence, expressions); • The control sequence includes a constant string to be printed, e.g., "Result: ", and control symbols to be used to convert variables from their numeric values that are stored in the computer to printing format. • The expressions is the list of expressions whose values are to be printed out. Each expression is separated by a comma. This is optional. // Java int x = 5; float y = 10.3f; System.out.println("hello " + x + " bye " + y); // C int x = 5; float y = 10.3; printf("hello %d bye %f", x, y);
  • 17. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 17 #include <stdio.h> void main () { int i, n = 5; printf("Hi, please enter an integer: "); // input: scanf (control sequence, &variable1, ... &variablen); // &variable: address of the variable. scanf("%d", &i); // input function if (i > n) n = n + i; else n = n - i; printf("i = %d, n = %dn", i, n); //output function } Input
  • 18. Javier Gonzalez-Sanchez | CSE 240 | Fall 2017 | 18 Control Statements These that you know, work in the same way • for, while, do/while • if/else, switch But, there are not boolean values. Zero is false and any other number is true. The following program is correct and print “Hello”
  • 19. CSE240 – Introduction to Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2017 Disclaimer. These slides can only be used as study material for the class CSE240 at ASU. They cannot be distributed or used for another purpose.