SlideShare a Scribd company logo
1 of 14
Dale RobertsDale Roberts
Department of Computer and Information Science,
School of Science, IUPUI
A First C Program
Dale Roberts
#include <stdio.h> /* I/O header file */
main()
{
printf(“Hello world ”);
printf(“Welcome to CSCI230n“);
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
 Variable 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
 Four 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
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
 Literal
 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>
Dale Roberts
 String 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
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
1 38
‘a’ + ‘b’ + ‘c’ = 97 + 98 + 99 = 294 = 256 + 38
in the memory
Dale Roberts
 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
 Each variable has a name, address, type, and value
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
 Write a program to take two numbers as input data
and print their sum, their difference, their product and
their 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
 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
#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

Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Abou Bakr Ashraf
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambalajatin batra
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++Ameer Khan
 
C++
C++C++
C++k v
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1Hossein Zahed
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 

What's hot (20)

Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
C++
C++C++
C++
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centre
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Visula C# Programming Lecture 2
Visula C# Programming Lecture 2
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
C++
C++C++
C++
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 

Viewers also liked

전망좋은펜션『BU797』.『COM』제주여행싸게가기
전망좋은펜션『BU797』.『COM』제주여행싸게가기전망좋은펜션『BU797』.『COM』제주여행싸게가기
전망좋은펜션『BU797』.『COM』제주여행싸게가기hdflkgjdo
 
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...Tanay Kumar Das
 
ApresentaçãO Primeira AudiêNcia 1
ApresentaçãO Primeira AudiêNcia 1ApresentaçãO Primeira AudiêNcia 1
ApresentaçãO Primeira AudiêNcia 1José Augusto Fiorin
 
외도유람선『LG777』.『XYZ』하이원
외도유람선『LG777』.『XYZ』하이원외도유람선『LG777』.『XYZ』하이원
외도유람선『LG777』.『XYZ』하이원hdflkgjdo
 
CIDCO Estate Management Software new
CIDCO Estate Management Software newCIDCO Estate Management Software new
CIDCO Estate Management Software newFaiyaz Khan
 
마녀사냥
마녀사냥마녀사냥
마녀사냥hdflkgjdo
 
Present to influence - October 2013
Present to influence - October 2013Present to influence - October 2013
Present to influence - October 2013Joni Axon
 
Introduction to ASP .Net
Introduction to ASP .NetIntroduction to ASP .Net
Introduction to ASP .Netayman diab
 
Få succes med Social Selling
Få succes med Social SellingFå succes med Social Selling
Få succes med Social SellingBusiness Danmark
 
Introduction to asp .net
Introduction to asp .netIntroduction to asp .net
Introduction to asp .netumesh patil
 
Hacemos escalada5 ºb
Hacemos escalada5 ºbHacemos escalada5 ºb
Hacemos escalada5 ºbPuy Mateo
 
El quijote cía
El quijote cíaEl quijote cía
El quijote cíaPuy Mateo
 
Administrasi sekolah ppt
Administrasi sekolah pptAdministrasi sekolah ppt
Administrasi sekolah pptSutoyo Biwi
 
анара мусина+необычный парк+ предпринематели
анара мусина+необычный парк+ предпринемателианара мусина+необычный парк+ предпринематели
анара мусина+необычный парк+ предпринемателиAnara Mussina
 

Viewers also liked (18)

전망좋은펜션『BU797』.『COM』제주여행싸게가기
전망좋은펜션『BU797』.『COM』제주여행싸게가기전망좋은펜션『BU797』.『COM』제주여행싸게가기
전망좋은펜션『BU797』.『COM』제주여행싸게가기
 
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...
Ssc stenographer grade c & d exam 2012 coaching at cheap rate with free study...
 
ApresentaçãO Primeira AudiêNcia 1
ApresentaçãO Primeira AudiêNcia 1ApresentaçãO Primeira AudiêNcia 1
ApresentaçãO Primeira AudiêNcia 1
 
외도유람선『LG777』.『XYZ』하이원
외도유람선『LG777』.『XYZ』하이원외도유람선『LG777』.『XYZ』하이원
외도유람선『LG777』.『XYZ』하이원
 
CIDCO Estate Management Software new
CIDCO Estate Management Software newCIDCO Estate Management Software new
CIDCO Estate Management Software new
 
마녀사냥
마녀사냥마녀사냥
마녀사냥
 
Css
Css Css
Css
 
Present to influence - October 2013
Present to influence - October 2013Present to influence - October 2013
Present to influence - October 2013
 
Introduction to ASP .Net
Introduction to ASP .NetIntroduction to ASP .Net
Introduction to ASP .Net
 
Få succes med Social Selling
Få succes med Social SellingFå succes med Social Selling
Få succes med Social Selling
 
Salgstrends 2017
Salgstrends 2017  Salgstrends 2017
Salgstrends 2017
 
Introduction to asp .net
Introduction to asp .netIntroduction to asp .net
Introduction to asp .net
 
Hacemos escalada5 ºb
Hacemos escalada5 ºbHacemos escalada5 ºb
Hacemos escalada5 ºb
 
Miercoles
MiercolesMiercoles
Miercoles
 
El quijote cía
El quijote cíaEl quijote cía
El quijote cía
 
Administrasi sekolah ppt
Administrasi sekolah pptAdministrasi sekolah ppt
Administrasi sekolah ppt
 
анара мусина+необычный парк+ предпринематели
анара мусина+необычный парк+ предпринемателианара мусина+необычный парк+ предпринематели
анара мусина+необычный парк+ предпринематели
 
Y jugamos
Y jugamosY jugamos
Y jugamos
 

Similar to C language (20)

C language first program
C language first programC language first program
C language first program
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
First c program
First c programFirst c program
First c program
 
C tutorial
C tutorialC tutorial
C tutorial
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
 
C programming language
C programming languageC programming language
C programming language
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
 
AssignmentThe purpose of this assignment is to get you familiar .docx
AssignmentThe purpose of this assignment is to get you familiar .docxAssignmentThe purpose of this assignment is to get you familiar .docx
AssignmentThe purpose of this assignment is to get you familiar .docx
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Cpprm
CpprmCpprm
Cpprm
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Cbasic
CbasicCbasic
Cbasic
 
Cbasic
CbasicCbasic
Cbasic
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
 
Cbasic
CbasicCbasic
Cbasic
 

More from umesh patil

Array in c language
Array in c languageArray in c language
Array in c languageumesh patil
 
Array in c language
Array in c language Array in c language
Array in c language umesh patil
 
Jquery Preparation
Jquery PreparationJquery Preparation
Jquery Preparationumesh patil
 
Static and dynamic polymorphism
Static and dynamic polymorphismStatic and dynamic polymorphism
Static and dynamic polymorphismumesh patil
 
Html and css presentation
Html and css presentationHtml and css presentation
Html and css presentationumesh patil
 
Html Presentation
Html PresentationHtml Presentation
Html Presentationumesh patil
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals umesh patil
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
css and wordpress
css and wordpresscss and wordpress
css and wordpressumesh patil
 
css and wordpress
css and wordpresscss and wordpress
css and wordpressumesh patil
 
Array in c language
Array in c language Array in c language
Array in c language umesh patil
 

More from umesh patil (20)

Ccna security
Ccna security Ccna security
Ccna security
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Array in c language
Array in c language Array in c language
Array in c language
 
Jquery Preparation
Jquery PreparationJquery Preparation
Jquery Preparation
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Static and dynamic polymorphism
Static and dynamic polymorphismStatic and dynamic polymorphism
Static and dynamic polymorphism
 
C language
C language C language
C language
 
Html and css presentation
Html and css presentationHtml and css presentation
Html and css presentation
 
Html Presentation
Html PresentationHtml Presentation
Html Presentation
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
 
Java script
Java scriptJava script
Java script
 
Function in c program
Function in c programFunction in c program
Function in c program
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
Php vs asp
Php vs aspPhp vs asp
Php vs asp
 
Ccna security
Ccna security Ccna security
Ccna security
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Array in c language
Array in c language Array in c language
Array in c language
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

C language

  • 1. Dale RobertsDale Roberts Department of Computer and Information Science, School of Science, IUPUI A First C Program
  • 2. Dale Roberts #include <stdio.h> /* I/O header file */ main() { printf(“Hello world ”); printf(“Welcome to CSCI230n“); 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  Variable 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  Four 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 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  Literal  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>
  • 8. Dale Roberts  String 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
  • 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 1 38 ‘a’ + ‘b’ + ‘c’ = 97 + 98 + 99 = 294 = 256 + 38 in the memory
  • 10. Dale Roberts  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  Each variable has a name, address, type, and value 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  Write a program to take two numbers as input data and print their sum, their difference, their product and their 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  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 #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