SlideShare a Scribd company logo
Dale Roberts
Department of Computer and Information Science,
School of Science, IUPUI
Dale Roberts, Lecturer
Computer Science, IUPUI
E-mail: droberts@cs.iupui.edu
A First C Program
Dale Roberts
Try Your First C ProgramTry Your First C Program
#include <stdio.h> /* I/O header file */#include <stdio.h> /* I/O header file */
main()main()
{{
printf(“Hello world ”);printf(“Hello world ”);
printf(“Welcome to CSCI230n“);printf(“Welcome to CSCI230n“);
printf(“I am John Smithn”);printf(“I am John Smithn”);
}}
A C program contains one or more functions
main() is the function name of your main (root) program
{ }: braces (left & right) to construct a block containing the statements of a
function
Every statement must end with a ;
 is called an escape character
n is an example of an escape sequence which indicates newline
Other escape sequences are: t r a  ”
Exercise: Use any editor to type and then save your first program as main.c
% gcc main.c
% a.out and observe its result.
header file – contains I/O routines
pre-processor directive
one statement
main must be present in each C program
statement terminator
Indicates a
program
building
block called
function
comment
Dale Roberts
IdentifiersIdentifiers
Variable identifiersVariable identifiers
Begin with a letter or underscore: A-Z, a-z, _
The rest of the name can be letters, underscore, or digits
Guarantee that east least the first 8 characters are significant (those
come after the 8th character will be ignored) while most of C compiler
allows 32 significant characters.
Example:
_abc ABC Time time _a1 abcdefgh
abcdefghi (may be the same as abcdefgh)
Case sensitive
Keywords: reserved names (lexical tokens)
auto double if static break else int struct
case entry long switch char extern register
typedef float return union do go sizeof continue


Dale Roberts
Fundamental Data TypeFundamental Data Type
Four Data TypesFour Data Types (assume 2’s complement, byte machine)
Data Type Abbreviation Size
(byte)
Range
char char 1 -128 ~ 127
unsigned char 1 0 ~ 255
int
int 2 or 4 -215
~ 215
-1 or -231
~ 231
-1
unsigned int unsigned 2 or 4 0 ~ 65535 or 0 ~ 232
-1
short int short 2 -32768 ~ 32767
unsigned short int unsigned short 2 0 ~ 65535
long int long 4 -231
~ 231
-1
unsigned long int unsigned long 4 0 ~ 232
-1
float 4
double 8
Note: 27
= 128, 215
=32768, 231
= 2147483648
Complex and double complex are not available
Dale Roberts
Variable DeclarationsVariable Declarations
type v1,v2,v3, 
, vn
Example:
int i;
int j;
float k;
char c;
short int x;
long int y;
unsigned int z;
int a1, a2, a3, a4, a5;
Dale Roberts
Numeric, Char, String LiteralsNumeric, Char, String Literals
LiteralLiteral
Numeric literal
fixed-point
octal O32 (= 24D) (covered later)
hexadecimal OxFE or Oxfe (=254D) (covered later)
decimal int 32
long (explicit) 32L or 32l
an ordinary integer literal that is too long to fit in an int is also too
long for long
floating-point
No single precision is used; always use double for literal
Example:
1.23
123.456e-7
0.12E
Dale Roberts
‱ Character literal (covered later)
‱ American Standard Code for Information Interchange (ASCII)
‱ Printable: single space 32
‘0’ - ‘9’ 48 - 57
‘A’ - ‘Z’ 65 - 90
‘a’ - ‘z’ 97 - 122
‱ Nonprintable and special meaning chars
‘n’ new line 10 ‘t’ tab 9
‘’ back slash 9 ‘’’ single quote 39
‘0’ null 0 ‘b’ back space 8
‘f’ formfeed 12 ’r’ carriage return 13
‘”’ double quote 34
‘ddd’ arbitrary bit pattern using 1-3 octal digits
‘Xdd’ for Hexadecimal mode
‘017’ or ‘17’ Shift-Ins, ^O
‘04’ or ‘4’ or ‘004’ EOT (^D)
‘033’ or ‘X1B’ <esc>
Numeric, Char, String LiteralsNumeric, Char, String Literals
Dale Roberts
String LiteralString Literal
will be covered in Array section
String is a array of chars but ended by ‘0’
String literal is allocated in a continuous memory space of
Data Segment, so it can not be rewritten
Example: “ABCD”
...A B C D ‘0’
Ans: 13+1 = 14 bytes
Question: “I am a string” takes ? Bytes
4 chars but takes 5 byte spaces in memory
Numeric, Char, String LiteralsNumeric, Char, String Literals
Dale Roberts
‱ Character literals & ASCII codes:
char x;
x=‘a’; /* x = 97*/
Notes:
–‘a’ and “a” are different; why?
‘a’ is the literal 97
“a” is an array of character literals, { ‘a’, ‘0’} or {97, 0}
–“a” + “b” +”c” is invalid but ‘a’+’b’+’c’ = ? (hint: ‘a’ = 97 in ASCII)
–if the code used is not ASCII code, one should check out each
value of character
Numeric, Char, String LiteralsNumeric, Char, String Literals
1 38
‘a’ + ‘b’ + ‘c’ = 97 + 98 + 99 = 294 = 256 + 38
in the memory
Dale Roberts
InitializationInitialization
If a variable is not initialized, the value of
variable may be either 0 or garbage depending
on the storage class of the variable.
int i=5;
float x=1.23;
char c=‘A’;
int i=1, j,k=5;
char c1 = ‘A’, c2 = 97;
float x=1.23, y=0.1;
Dale Roberts
Memory ConceptsMemory Concepts
Each variable has a name, address, type, andEach variable has a name, address, type, and
valuevalue
1) int x;
2) scanf(“%d”, &x);
3) user inputs 10
4) x = 200;
After the execution of (1) x
After the execution of (2) x
After the execution of (3) x
After the execution of (4) x
Previous value of x was overwritten
10
200
Dale Roberts
Sample ProblemSample Problem
Write a program to take two numbers as input data andWrite a program to take two numbers as input data and
print their sum, their difference, their product and theirprint their sum, their difference, their product and their
quotient.quotient.
Problem Inputs
float x, y; /* two items */
problem Output
float sum; /* sum of x and y */
float difference; /* difference of x and y */
float product; /* product of x and y */
float quotient; /* quotient of x divided by y */
Dale Roberts
Sample ProblemSample Problem (cont.)(cont.)
Pseudo Code:Pseudo Code:
Declare variables of x and y;
Prompt user to input the value of x and y;
Print the sum of x and y;
Print the difference of x and y;
Print the product of x and y;
If y not equal to zero, print the quotient of x divided by y
Dale Roberts
Example ProgramExample Program
#include <stdio.h>
int main(void)
{
float x,y;
float sum;
printf(“Enter the value of x:”);
scanf(“%f”, &x);
printf(“nEnter the value of y:”);
scanf(“%f”, &y);
sum = x + y;
printf(“nthe sum of x and y is:%f”,sum);
printf(“nthe sum of x and y is:%f”,x+y);
printf(“nthe difference of x and y is:%f”,x-y);
printf(“nthe product of x and y is:%f”,x*y);
if (y != 0)
printf(“nthe quotient of x divided by y is:%f”,x/y);
else
printf(“nquotient of x divided by y does not
exist!n”);
return(0);
}
function
‱ name
‱ list of argument along with their types
‱ return value and its type
‱ Body
inequality operator

More Related Content

What's hot (20)

PPS
C++ Language
Vidyacenter
 
PDF
C++
Shyam Khant
 
PPTX
Learn c++ Programming Language
Steve Johnson
 
PPTX
45 Days C++ Programming Language Training in Ambala
jatin batra
 
PDF
Python Programming
Saravanan T.M
 
PPT
Constants in C Programming
programming9
 
PDF
Zaridah lecture2
Aziz Sahat
 
PPTX
C++ Programming Language Training in Ambala ! Batra Computer Centre
jatin batra
 
PPT
Basic concept of c++
shashikant pabari
 
PPT
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
PDF
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
PDF
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
 
PPT
Data Handling
Praveen M Jigajinni
 
PPT
Visula C# Programming Lecture 7
Abou Bakr Ashraf
 
PPTX
C Language (All Concept)
sachindane
 
PPTX
Introduction to Python , Overview
NB Veeresh
 
PPTX
datatypes and variables in c language
Rai University
 
PPTX
What is c
Nitesh Saitwal
 
PPTX
C# overview part 1
sagaroceanic11
 
C++ Language
Vidyacenter
 
Learn c++ Programming Language
Steve Johnson
 
45 Days C++ Programming Language Training in Ambala
jatin batra
 
Python Programming
Saravanan T.M
 
Constants in C Programming
programming9
 
Zaridah lecture2
Aziz Sahat
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
jatin batra
 
Basic concept of c++
shashikant pabari
 
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
 
Data Handling
Praveen M Jigajinni
 
Visula C# Programming Lecture 7
Abou Bakr Ashraf
 
C Language (All Concept)
sachindane
 
Introduction to Python , Overview
NB Veeresh
 
datatypes and variables in c language
Rai University
 
What is c
Nitesh Saitwal
 
C# overview part 1
sagaroceanic11
 

Viewers also liked (20)

PPTX
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
PPSX
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
PPT
Basics of C programming
avikdhupar
 
PPTX
First c program
NageswaraRao Gogisetti
 
PPTX
File in C programming
Samsil Arefin
 
DOC
List of programs for practical file
swatisinghal
 
PPTX
introduction to c language
Rai University
 
DOCX
servlet programming
Rumman Ansari
 
PDF
C Language Program
Warawut
 
PPT
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
PPTX
CHAPTER 3
mohd_mizan
 
PPT
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
PPT
Introduction to Basic C programming 01
Wingston
 
DOCX
C program report tips
Harry Pott
 
PPT
File in C Programming
Sonya Akter Rupa
 
PPTX
My first program in c, hello world !
Rumman Ansari
 
PPSX
Complete C programming Language Course
Vivek Singh Chandel
 
PPTX
How c program execute in c program
Rumman Ansari
 
PPTX
Library Management System Project in C
codewithc
 
PPSX
C programming basics
argusacademy
 
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 
Basics of C programming
avikdhupar
 
First c program
NageswaraRao Gogisetti
 
File in C programming
Samsil Arefin
 
List of programs for practical file
swatisinghal
 
introduction to c language
Rai University
 
servlet programming
Rumman Ansari
 
C Language Program
Warawut
 
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
CHAPTER 3
mohd_mizan
 
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Introduction to Basic C programming 01
Wingston
 
C program report tips
Harry Pott
 
File in C Programming
Sonya Akter Rupa
 
My first program in c, hello world !
Rumman Ansari
 
Complete C programming Language Course
Vivek Singh Chandel
 
How c program execute in c program
Rumman Ansari
 
Library Management System Project in C
codewithc
 
C programming basics
argusacademy
 
Ad

Similar to C language first program (20)

PPS
T02 a firstcprogram
princepavan
 
PDF
C Programming Assignment
Vijayananda Mohire
 
PPTX
Introduction to C language programming.pptx
OVIDMAMAH
 
DOC
C language
SMS2007
 
DOCX
Report on c and c++
oggyrao
 
PPTX
Introduction to C Programming - R.D.Sivakumar
Sivakumar R D .
 
PDF
Data structure & Algorithms - Programming in C
babuk110
 
PDF
C SLIDES PREPARED BY M V B REDDY
Malikireddy Bramhananda Reddy
 
PPTX
unit 1 cpds.pptx
madhurij54
 
PPTX
C
PRADEEPA R
 
PPT
Ch2 introduction to c
Hattori Sidek
 
PPT
Unit 1 Built in Data types in C language.ppt
pubgnewstate1620
 
PPTX
1.getting started with c
Hardik gupta
 
PPTX
Data Type in C Programming
Qazi Shahzad Ali
 
ODP
CProgrammingTutorial
Muthuselvam RS
 
PPTX
Variable declaration
Mark Leo Tarectecan
 
PPTX
Each n Every topic of C Programming.pptx
snnbarot
 
PPTX
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
PPTX
c_pro_introduction.pptx
RohitRaj744272
 
PPTX
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
T02 a firstcprogram
princepavan
 
C Programming Assignment
Vijayananda Mohire
 
Introduction to C language programming.pptx
OVIDMAMAH
 
C language
SMS2007
 
Report on c and c++
oggyrao
 
Introduction to C Programming - R.D.Sivakumar
Sivakumar R D .
 
Data structure & Algorithms - Programming in C
babuk110
 
C SLIDES PREPARED BY M V B REDDY
Malikireddy Bramhananda Reddy
 
unit 1 cpds.pptx
madhurij54
 
Ch2 introduction to c
Hattori Sidek
 
Unit 1 Built in Data types in C language.ppt
pubgnewstate1620
 
1.getting started with c
Hardik gupta
 
Data Type in C Programming
Qazi Shahzad Ali
 
CProgrammingTutorial
Muthuselvam RS
 
Variable declaration
Mark Leo Tarectecan
 
Each n Every topic of C Programming.pptx
snnbarot
 
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
c_pro_introduction.pptx
RohitRaj744272
 
PPS_unit_2_gtu_sem_2_year_2023_GTUU.pptx
ZwecklosSe
 
Ad

More from NIKHIL KRISHNA (6)

PPS
C language computer introduction to the computer hardware
NIKHIL KRISHNA
 
PDF
All surface empty bottle inspection(ASEBI) FULL DOCUMENTATION
NIKHIL KRISHNA
 
PPTX
COCO-COLA MAINTAINCE AND TRAINING(ASEBI)
NIKHIL KRISHNA
 
PPTX
ALL SURFACE EMPTY BOTTLE INSPECTION TRAINING
NIKHIL KRISHNA
 
PPT
EMPTY BOTTLE INSPECTION MACHINE
NIKHIL KRISHNA
 
PPTX
SOLAR TREE
NIKHIL KRISHNA
 
C language computer introduction to the computer hardware
NIKHIL KRISHNA
 
All surface empty bottle inspection(ASEBI) FULL DOCUMENTATION
NIKHIL KRISHNA
 
COCO-COLA MAINTAINCE AND TRAINING(ASEBI)
NIKHIL KRISHNA
 
ALL SURFACE EMPTY BOTTLE INSPECTION TRAINING
NIKHIL KRISHNA
 
EMPTY BOTTLE INSPECTION MACHINE
NIKHIL KRISHNA
 
SOLAR TREE
NIKHIL KRISHNA
 

Recently uploaded (20)

PPTX
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
PPTX
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PDF
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
PPTX
drones for disaster prevention response.pptx
NawrasShatnawi1
 
PDF
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PPT
inherently safer design for engineering.ppt
DhavalShah616893
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PPTX
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PDF
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
PPTX
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Benefits_^0_Challigi😙🏡💐8fenges[1].pptx
akghostmaker
 
Presentation on Foundation Design for Civil Engineers.pptx
KamalKhan563106
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
UNIT-4-FEEDBACK AMPLIFIERS AND OSCILLATORS (1).pdf
Sridhar191373
 
drones for disaster prevention response.pptx
NawrasShatnawi1
 
MOBILE AND WEB BASED REMOTE BUSINESS MONITORING SYSTEM
ijait
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
inherently safer design for engineering.ppt
DhavalShah616893
 
Thermal runway and thermal stability.pptx
godow93766
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
BioSensors glucose monitoring, cholestrol
nabeehasahar1
 
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 

C language first program

  • 1. Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI E-mail: [email protected] A First C Program
  • 2. Dale Roberts Try Your First C ProgramTry Your First C Program #include <stdio.h> /* I/O header file */#include <stdio.h> /* I/O header file */ main()main() {{ printf(“Hello world ”);printf(“Hello world ”); printf(“Welcome to CSCI230n“);printf(“Welcome to CSCI230n“); printf(“I am John Smithn”);printf(“I am John Smithn”); }} A C program contains one or more functions main() is the function name of your main (root) program { }: braces (left & right) to construct a block containing the statements of a function Every statement must end with a ; is called an escape character n is an example of an escape sequence which indicates newline Other escape sequences are: t r a ” Exercise: Use any editor to type and then save your first program as main.c % gcc main.c % a.out and observe its result. header file – contains I/O routines pre-processor directive one statement main must be present in each C program statement terminator Indicates a program building block called function comment
  • 3. Dale Roberts IdentifiersIdentifiers Variable identifiersVariable identifiers Begin with a letter or underscore: A-Z, a-z, _ The rest of the name can be letters, underscore, or digits Guarantee that east least the first 8 characters are significant (those come after the 8th character will be ignored) while most of C compiler allows 32 significant characters. Example: _abc ABC Time time _a1 abcdefgh abcdefghi (may be the same as abcdefgh) Case sensitive Keywords: reserved names (lexical tokens) auto double if static break else int struct case entry long switch char extern register typedef float return union do go sizeof continue 

  • 4. Dale Roberts Fundamental Data TypeFundamental Data Type Four Data TypesFour Data Types (assume 2’s complement, byte machine) Data Type Abbreviation Size (byte) Range char char 1 -128 ~ 127 unsigned char 1 0 ~ 255 int int 2 or 4 -215 ~ 215 -1 or -231 ~ 231 -1 unsigned int unsigned 2 or 4 0 ~ 65535 or 0 ~ 232 -1 short int short 2 -32768 ~ 32767 unsigned short int unsigned short 2 0 ~ 65535 long int long 4 -231 ~ 231 -1 unsigned long int unsigned long 4 0 ~ 232 -1 float 4 double 8 Note: 27 = 128, 215 =32768, 231 = 2147483648 Complex and double complex are not available
  • 5. Dale Roberts Variable DeclarationsVariable Declarations type v1,v2,v3, 
, vn Example: int i; int j; float k; char c; short int x; long int y; unsigned int z; int a1, a2, a3, a4, a5;
  • 6. Dale Roberts Numeric, Char, String LiteralsNumeric, Char, String Literals LiteralLiteral Numeric literal fixed-point octal O32 (= 24D) (covered later) hexadecimal OxFE or Oxfe (=254D) (covered later) decimal int 32 long (explicit) 32L or 32l an ordinary integer literal that is too long to fit in an int is also too long for long floating-point No single precision is used; always use double for literal Example: 1.23 123.456e-7 0.12E
  • 7. Dale Roberts ‱ Character literal (covered later) ‱ American Standard Code for Information Interchange (ASCII) ‱ Printable: single space 32 ‘0’ - ‘9’ 48 - 57 ‘A’ - ‘Z’ 65 - 90 ‘a’ - ‘z’ 97 - 122 ‱ Nonprintable and special meaning chars ‘n’ new line 10 ‘t’ tab 9 ‘’ back slash 9 ‘’’ single quote 39 ‘0’ null 0 ‘b’ back space 8 ‘f’ formfeed 12 ’r’ carriage return 13 ‘”’ double quote 34 ‘ddd’ arbitrary bit pattern using 1-3 octal digits ‘Xdd’ for Hexadecimal mode ‘017’ or ‘17’ Shift-Ins, ^O ‘04’ or ‘4’ or ‘004’ EOT (^D) ‘033’ or ‘X1B’ <esc> Numeric, Char, String LiteralsNumeric, Char, String Literals
  • 8. Dale Roberts String LiteralString Literal will be covered in Array section String is a array of chars but ended by ‘0’ String literal is allocated in a continuous memory space of Data Segment, so it can not be rewritten Example: “ABCD” ...A B C D ‘0’ Ans: 13+1 = 14 bytes Question: “I am a string” takes ? Bytes 4 chars but takes 5 byte spaces in memory Numeric, Char, String LiteralsNumeric, Char, String Literals
  • 9. Dale Roberts ‱ Character literals & ASCII codes: char x; x=‘a’; /* x = 97*/ Notes: –‘a’ and “a” are different; why? ‘a’ is the literal 97 “a” is an array of character literals, { ‘a’, ‘0’} or {97, 0} –“a” + “b” +”c” is invalid but ‘a’+’b’+’c’ = ? (hint: ‘a’ = 97 in ASCII) –if the code used is not ASCII code, one should check out each value of character Numeric, Char, String LiteralsNumeric, Char, String Literals 1 38 ‘a’ + ‘b’ + ‘c’ = 97 + 98 + 99 = 294 = 256 + 38 in the memory
  • 10. Dale Roberts InitializationInitialization If a variable is not initialized, the value of variable may be either 0 or garbage depending on the storage class of the variable. int i=5; float x=1.23; char c=‘A’; int i=1, j,k=5; char c1 = ‘A’, c2 = 97; float x=1.23, y=0.1;
  • 11. Dale Roberts Memory ConceptsMemory Concepts Each variable has a name, address, type, andEach variable has a name, address, type, and valuevalue 1) int x; 2) scanf(“%d”, &x); 3) user inputs 10 4) x = 200; After the execution of (1) x After the execution of (2) x After the execution of (3) x After the execution of (4) x Previous value of x was overwritten 10 200
  • 12. Dale Roberts Sample ProblemSample Problem Write a program to take two numbers as input data andWrite a program to take two numbers as input data and print their sum, their difference, their product and theirprint their sum, their difference, their product and their quotient.quotient. Problem Inputs float x, y; /* two items */ problem Output float sum; /* sum of x and y */ float difference; /* difference of x and y */ float product; /* product of x and y */ float quotient; /* quotient of x divided by y */
  • 13. Dale Roberts Sample ProblemSample Problem (cont.)(cont.) Pseudo Code:Pseudo Code: Declare variables of x and y; Prompt user to input the value of x and y; Print the sum of x and y; Print the difference of x and y; Print the product of x and y; If y not equal to zero, print the quotient of x divided by y
  • 14. Dale Roberts Example ProgramExample Program #include <stdio.h> int main(void) { float x,y; float sum; printf(“Enter the value of x:”); scanf(“%f”, &x); printf(“nEnter the value of y:”); scanf(“%f”, &y); sum = x + y; printf(“nthe sum of x and y is:%f”,sum); printf(“nthe sum of x and y is:%f”,x+y); printf(“nthe difference of x and y is:%f”,x-y); printf(“nthe product of x and y is:%f”,x*y); if (y != 0) printf(“nthe quotient of x divided by y is:%f”,x/y); else printf(“nquotient of x divided by y does not exist!n”); return(0); } function ‱ name ‱ list of argument along with their types ‱ return value and its type ‱ Body inequality operator