SlideShare a Scribd company logo
1 of 31
Programming in C
What is C?
C is a high level and general purpose
programming language that is ideal
for developing firmware or portable
applications.
C was developed at Bell Labs by Dennis
Ritchie for the Unix Operating system
in the early 1970s
C is strongly associated with UNIX, as it
was developed to write the UNIX
operating system.
Why Learn C?
It is one of the most popular programming
language in the world
If you know C, you will have no problem
learning other popular programming
languages such as Java, Python, C++, C#,
etc, as the syntax is similar
C is very fast, compared to other
programming languages, like Java and
Python
C is very versatile; it can be used in both
applications and technologies
Get Started With C
To start using C, you need two things:
A text editor, like Notepad, to write C code
A compiler, like GCC, to translate the C code into a
language that the computer will understand
An IDE (Integrated Development Environment) is
used to edit AND compile the code.
Popular IDE's include Code::Blocks, Eclipse, and Visual
Studio. These are all free, and they can be used to
both edit and debug C code.
C Syntax
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Line 1: #include <stdio.h> is a header file library that lets us
work with input and output functions, such as printf() (used
in line 4). Header files add functionality to C programs.
Line 2: A blank line. C ignores white space. But we use it
to make the code more readable.
Line 3: Another thing that always appear in a C
program, is main(). This is called a function. Any code
inside its curly brackets {} will be executed.
Line 4: printf() is a function used to output/print text to
the screen. In our example it will output "Hello World".
Note that: Every C statement ends with a
semicolon ;
Note: The body of int main() could also been
written as:
int main(){printf("Hello World!");return 0;}
Line 5: return 0 ends the main() function.
Line 6: Do not forget to add the closing
curly bracket } to actually end the main
function.
C Output (Print Text)
The printf() function is used to output values/print
text:
You can add as many printf() functions as you want.
However, note that it does not insert a new line at
the end of the output:
#include <stdio.h>
int main() {
printf("Hello World!");
printf("I am learning C.");
return 0;
}
New Lines
To insert a new line, you can use the n
character:
Example
#include <stdio.h>
int main() {
printf("Hello World!n");
printf("I am learning C.");
return 0;
}
You can also output multiple lines with a single
printf() function. However, be aware that this will
make the code harder to read:
#include <stdio.h>
int main() {
printf("Hello World!nI am learning C.nAnd it is
awesome!");
return 0;
}
Two n characters after each other will create a blank line:
What is n exactly?
The newline character (n) is called an escape
sequence, and it forces the cursor to change its
position to the beginning of the next line on the
screen. This results in a new line.
Examples of other valid escape sequences are:
Escape Sequence Description
t Creates a horizontal tab
 Inserts a backslash character ()
" Inserts a double quote character
C Variables
Variables are containers for storing data values.
In C, there are different types of variables (defined with
different keywords), for example:
int - stores integers (whole numbers), without
decimals, such as 123 or -123
float - stores floating point numbers, with decimals,
such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char
values are surrounded by single quotes
To create a variable, specify
the type and assign it a value:
Declaring (Creating) Variables
Syntax
type variableName = value;
C Variable Names
All C variables must be identified with unique
names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names in
order to create understandable and maintainable
code:
To output variables in C, you must get familiar with
something called "format specifiers".
Format Specifiers
Format specifiers are used together with the printf()
function to tell the compiler what type of data the
variable is storing. It is basically a placeholder for the
variable value.
A format specifier starts with a percentage sign %,
followed by a character.
For example, to output the value of an int variable, you
must use the format specifier %d or %i surrounded by
double quotes, inside the printf() function:
Example
// Create variables
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character
// Print variables
printf("%dn", myNum);
printf("%fn", myFloatNum);
printf("%cn", myLetter);
To print other types,
use %c for char
and %f for float:
To combine both text and a variable, separate them
with a comma inside the printf() function:
Example
int myNum = 5;
printf("My favorite number is: %d", myNum);
To print different types in a single printf() function,
you can use the following:
#include <stdio.h>
int main() {
int myNum = 5;
char myLetter = 'D';
printf("My number is %d and my letter is %c", myNum, myLetter);
return 0;
}
C Variable Names
All C variables must be identified with unique
names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names
in order to create understandable and maintainable
code:
C Data Types
As explained in the Variables chapter, a variable in C
must be a specified data type, and you must use a
format specifier inside the printf() function to display
it:
#include <stdio.h>
int main() {
// Create variables
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character
// Print variables
printf("%dn", myNum);
printf("%fn", myFloatNum);
printf("%cn", myLetter);
return 0;
}
Basic Data Types
The data type specifies the size and type of
information the variable will store.
Data Type Size Description
int 2 or 4 bytes Stores whole numbers, without
decimals.
float 4 bytes Stores fractional numbers,
containing one or more decimals.
Sufficient for storing 7 decimal
digits.
Double 8 bytes Stores fractional numbers,
containing one or more decimals.
Sufficient for storing 15 decimal
digits.
char 1 byte Stores a single
character/letter/number, or ASCII
values.
Basic Format Specifiers
Format Specifier Data Type
%d or %i int
%f float
%lf double
%c char
%s Used for strings
Constants
When you don't want others (or yourself) to
override existing variable values, use the const
keyword (this will declare the variable as "constant",
which means unchangeable and read-only):
Notes On Constants
When you declare a constant variable, it must be
assigned with a value:
Example
Like this:
const int minutesPerHour = 60;
Prepared by:
Teresita C. Dapulase
Reference:
https://www.w3schools.com/c/index.php

More Related Content

Similar to Programming in C.pptx

Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing TutorialMahira Banu
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c programAlamgir Hossain
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
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 Dubeykiranrajat
 

Similar to Programming in C.pptx (20)

Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Chapter3
Chapter3Chapter3
Chapter3
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Cnotes
CnotesCnotes
Cnotes
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C presentation book
C presentation bookC presentation book
C presentation book
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
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
 

Recently uploaded

IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Programming in C.pptx

  • 2. What is C? C is a high level and general purpose programming language that is ideal for developing firmware or portable applications.
  • 3. C was developed at Bell Labs by Dennis Ritchie for the Unix Operating system in the early 1970s C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
  • 4. Why Learn C? It is one of the most popular programming language in the world If you know C, you will have no problem learning other popular programming languages such as Java, Python, C++, C#, etc, as the syntax is similar C is very fast, compared to other programming languages, like Java and Python
  • 5. C is very versatile; it can be used in both applications and technologies Get Started With C To start using C, you need two things: A text editor, like Notepad, to write C code A compiler, like GCC, to translate the C code into a language that the computer will understand
  • 6. An IDE (Integrated Development Environment) is used to edit AND compile the code. Popular IDE's include Code::Blocks, Eclipse, and Visual Studio. These are all free, and they can be used to both edit and debug C code.
  • 7. C Syntax #include <stdio.h> int main() { printf("Hello World!"); return 0; } Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions, such as printf() (used in line 4). Header files add functionality to C programs.
  • 8. Line 2: A blank line. C ignores white space. But we use it to make the code more readable. Line 3: Another thing that always appear in a C program, is main(). This is called a function. Any code inside its curly brackets {} will be executed. Line 4: printf() is a function used to output/print text to the screen. In our example it will output "Hello World".
  • 9. Note that: Every C statement ends with a semicolon ; Note: The body of int main() could also been written as: int main(){printf("Hello World!");return 0;}
  • 10. Line 5: return 0 ends the main() function. Line 6: Do not forget to add the closing curly bracket } to actually end the main function.
  • 11. C Output (Print Text) The printf() function is used to output values/print text: You can add as many printf() functions as you want. However, note that it does not insert a new line at the end of the output: #include <stdio.h> int main() { printf("Hello World!"); printf("I am learning C."); return 0; }
  • 12. New Lines To insert a new line, you can use the n character: Example #include <stdio.h> int main() { printf("Hello World!n"); printf("I am learning C."); return 0; }
  • 13. You can also output multiple lines with a single printf() function. However, be aware that this will make the code harder to read: #include <stdio.h> int main() { printf("Hello World!nI am learning C.nAnd it is awesome!"); return 0; } Two n characters after each other will create a blank line:
  • 14. What is n exactly? The newline character (n) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
  • 15. Examples of other valid escape sequences are: Escape Sequence Description t Creates a horizontal tab Inserts a backslash character () " Inserts a double quote character
  • 16. C Variables Variables are containers for storing data values. In C, there are different types of variables (defined with different keywords), for example: int - stores integers (whole numbers), without decimals, such as 123 or -123 float - stores floating point numbers, with decimals, such as 19.99 or -19.99 char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
  • 17. To create a variable, specify the type and assign it a value: Declaring (Creating) Variables Syntax type variableName = value; C Variable Names All C variables must be identified with unique names.
  • 18. These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume). Note: It is recommended to use descriptive names in order to create understandable and maintainable code: To output variables in C, you must get familiar with something called "format specifiers".
  • 19. Format Specifiers Format specifiers are used together with the printf() function to tell the compiler what type of data the variable is storing. It is basically a placeholder for the variable value. A format specifier starts with a percentage sign %, followed by a character. For example, to output the value of an int variable, you must use the format specifier %d or %i surrounded by double quotes, inside the printf() function:
  • 20. Example // Create variables int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number char myLetter = 'D'; // Character // Print variables printf("%dn", myNum); printf("%fn", myFloatNum); printf("%cn", myLetter);
  • 21. To print other types, use %c for char and %f for float: To combine both text and a variable, separate them with a comma inside the printf() function: Example int myNum = 5; printf("My favorite number is: %d", myNum);
  • 22. To print different types in a single printf() function, you can use the following: #include <stdio.h> int main() { int myNum = 5; char myLetter = 'D'; printf("My number is %d and my letter is %c", myNum, myLetter); return 0; }
  • 23. C Variable Names All C variables must be identified with unique names. These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume). Note: It is recommended to use descriptive names in order to create understandable and maintainable code:
  • 24. C Data Types As explained in the Variables chapter, a variable in C must be a specified data type, and you must use a format specifier inside the printf() function to display it:
  • 25. #include <stdio.h> int main() { // Create variables int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number char myLetter = 'D'; // Character // Print variables printf("%dn", myNum); printf("%fn", myFloatNum); printf("%cn", myLetter); return 0; }
  • 26. Basic Data Types The data type specifies the size and type of information the variable will store.
  • 27. Data Type Size Description int 2 or 4 bytes Stores whole numbers, without decimals. float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 7 decimal digits. Double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits. char 1 byte Stores a single character/letter/number, or ASCII values.
  • 28. Basic Format Specifiers Format Specifier Data Type %d or %i int %f float %lf double %c char %s Used for strings
  • 29. Constants When you don't want others (or yourself) to override existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only): Notes On Constants When you declare a constant variable, it must be assigned with a value:
  • 30. Example Like this: const int minutesPerHour = 60;
  • 31. Prepared by: Teresita C. Dapulase Reference: https://www.w3schools.com/c/index.php